cornfield 0.23.0 → 0.25.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/brand.js +182 -0
- package/core/config.js +5 -0
- package/core/validate.js +19 -0
- package/explorer/check.js +3 -0
- package/explorer/cloud-model.js +4 -4
- package/explorer/corn-state.js +34 -0
- package/explorer/flows.js +1 -1
- package/explorer/forge-panel.js +36 -31
- package/explorer/house.js +4 -0
- package/explorer/index.html +106 -104
- package/explorer/layers.js +1 -1
- package/explorer/live-model.js +1 -1
- package/explorer/live.js +1 -1
- package/explorer/mockups-model.js +4 -3
- package/explorer/mockups.js +4 -0
- package/explorer/panels.js +1 -1
- package/explorer/plugins.js +43 -4
- package/explorer/proposal-model.js +1 -1
- package/explorer/proposal.js +4 -4
- package/explorer/renderer.js +1 -0
- package/explorer/review-tokens.js +2 -1
- package/explorer/review.js +2 -1
- package/explorer/runs-map.js +1 -0
- package/explorer/runs-view.js +6 -5
- package/explorer/scenario-ui.js +4 -2
- package/explorer/sheets.js +1 -0
- package/explorer/whatif.js +22 -21
- package/package.json +1 -1
- package/server/server.js +63 -3
package/explorer/panels.js
CHANGED
|
@@ -24,7 +24,7 @@ const $ = (id) => document.getElementById(id);
|
|
|
24
24
|
const code = (s) => `<code class="hx-code">${escHtml(s)}</code>`;
|
|
25
25
|
const nm = (id) => `<span class="hx-name">${escHtml(nameOf(id))}</span>`;
|
|
26
26
|
const line = (color, arrow, body) => `<div class="hx-line"><span class="hx-glyph" style="--glyph:${color}">${arrow}</span><span>${body}</span></div>`;
|
|
27
|
-
const section = (title, rows) => (rows.length ? `<div class="hx-sec"><strong class="hx-strong">${title}</strong>${rows.join('')}</div>` : '');
|
|
27
|
+
const section = (title, rows) => (rows.length ? `<div class="hx-sec" data-corn="section"><strong class="hx-strong">${title}</strong>${rows.join('')}</div>` : '');
|
|
28
28
|
const varList = (vars) => `<div class="hx-chips">${vars.map((v) => `<code class="hx-var">${escHtml(v)}</code>`).join('')}</div>`;
|
|
29
29
|
const edgesOf = (kind, side, id) => state.edges.filter((e) => e.kind === kind && e[side] === id);
|
|
30
30
|
|
package/explorer/plugins.js
CHANGED
|
@@ -37,26 +37,65 @@ export async function loadClientConfig(fetcher = (...a) => globalThis.fetch(...a
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/**
|
|
40
|
+
/** An <img> for a brand image (the server's same-origin URL): decorative, the button it sits in carries the name; `alt` only shows if it fails to load */
|
|
41
|
+
function brandImage(doc, src, kind, alt = '') {
|
|
42
|
+
const img = doc.createElement('img');
|
|
43
|
+
img.setAttribute('src', src);
|
|
44
|
+
img.setAttribute('alt', alt);
|
|
45
|
+
img.setAttribute('data-corn', `brand-${kind}`);
|
|
46
|
+
img.setAttribute('style', `height:${kind === 'logo' ? 22 : 18}px;width:auto;max-width:${kind === 'logo' ? 48 : 160}px;display:block`);
|
|
47
|
+
return img;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The repo's brand in the header (docs/config.md#brand): the logo takes the brand mark's place and the wordmark the title text, inside
|
|
52
|
+
* the same button, so its accessible name stays. The header text stays the repo's own title; `appName` replaces "cornfield" where
|
|
53
|
+
* cornfield names itself: the button's accessible name and the page's heading (the tab title and the manifest are the server's).
|
|
54
|
+
*/
|
|
55
|
+
function applyBrand(doc, brand, title) {
|
|
56
|
+
const button = doc.getElementById('cf-brand');
|
|
57
|
+
if (button && brand.appName) button.setAttribute('aria-label', `${brand.appName}: reset the view`);
|
|
58
|
+
const text = doc.getElementById('cf-title');
|
|
59
|
+
if (brand.logo && typeof doc.createElement === 'function') {
|
|
60
|
+
const mark = doc.getElementById('cf-mark');
|
|
61
|
+
if (mark) mark.replaceWith(brandImage(doc, brand.logo, 'logo'));
|
|
62
|
+
}
|
|
63
|
+
if (brand.wordmark && text && typeof doc.createElement === 'function') {
|
|
64
|
+
text.textContent = '';
|
|
65
|
+
text.appendChild(brandImage(doc, brand.wordmark, 'wordmark', title || brand.appName || ''));
|
|
66
|
+
}
|
|
67
|
+
const heading = doc.getElementById('cf-heading');
|
|
68
|
+
if (heading && brand.appName) heading.textContent = `${brand.appName}: the map`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The small "powered by cornfield" link that stays in the header when a repo brands cornfield */
|
|
72
|
+
function poweredBy(brand) {
|
|
73
|
+
if (!brand || typeof brand.poweredBy !== 'string' || !/^https:\/\//.test(brand.poweredBy)) return '';
|
|
74
|
+
return `<a class="hx-btn hx-btn--quiet" data-corn="powered-by" href="${escHtml(brand.poweredBy)}" target="_blank" rel="noreferrer">powered by cornfield</a>`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Puts the repo's title, brand and links in the header, and Sign out when the server says who is signed in */
|
|
41
78
|
export function applyBranding(doc, config) {
|
|
42
79
|
if (!config || !doc) return;
|
|
43
80
|
const title = doc.getElementById('cf-title');
|
|
44
81
|
if (title && config.title) title.textContent = config.title;
|
|
45
82
|
const heading = doc.getElementById('cf-heading');
|
|
46
83
|
if (heading && config.title) heading.textContent = `${config.title}: the map`;
|
|
84
|
+
if (config.brand) applyBrand(doc, config.brand, config.title);
|
|
47
85
|
initThemePicker(doc, config.theme);
|
|
48
86
|
const links = doc.getElementById('cf-links');
|
|
49
87
|
if (!links) return;
|
|
50
88
|
const html = Array.isArray(config.links) ? config.links
|
|
51
89
|
.filter((l) => l && typeof l.label === 'string' && /^(https?:\/\/|\/)/.test(String(l.href)))
|
|
52
|
-
.map((l) => `<a class="hx-chip-link hx-chip-link--indigo hx-only-xl" href="${escHtml(l.href)}" target="_blank" rel="noreferrer"><span class="hx-dot-sm"></span> ${escHtml(l.label)}</a>`)
|
|
90
|
+
.map((l) => `<a class="hx-chip-link hx-chip-link--indigo hx-only-xl" href="${escHtml(l.href)}" target="_blank" rel="noreferrer" data-corn="link"><span class="hx-dot-sm"></span> ${escHtml(l.label)}</a>`)
|
|
53
91
|
.join('') : '';
|
|
54
92
|
// A plain form: signing out is a same-origin POST (server/auth.js), no script needed. On a narrow phone only its icon
|
|
55
93
|
// shows (explorer.css); the words stay in the button for a screen reader
|
|
56
94
|
const signOut = config.signIn && typeof config.signIn.login === 'string'
|
|
57
|
-
? `<form class="cf-sign-out" method="post" action="/auth/sign-out"><button type="submit" class="hx-btn hx-btn--quiet" title="Signed in as ${escHtml(config.signIn.login)}"><span class="cf-sign-out-icon" aria-hidden="true">⎋</span><span class="cf-sign-out-text">Sign out</span></button></form>`
|
|
95
|
+
? `<form class="cf-sign-out" method="post" action="/auth/sign-out" data-corn="sign-out"><button type="submit" class="hx-btn hx-btn--quiet" title="Signed in as ${escHtml(config.signIn.login)}" data-corn-kind="quiet"><span class="cf-sign-out-icon" aria-hidden="true">⎋</span><span class="cf-sign-out-text">Sign out</span></button></form>`
|
|
58
96
|
: '';
|
|
59
|
-
|
|
97
|
+
const powered = poweredBy(config.brand);
|
|
98
|
+
if (html || powered || signOut) links.innerHTML = html + powered + signOut;
|
|
60
99
|
}
|
|
61
100
|
|
|
62
101
|
/**
|
|
@@ -172,7 +172,7 @@ export function proposalPanelHtml(item) {
|
|
|
172
172
|
const body = rows.map((r) => (item.mark === 'changed'
|
|
173
173
|
? `<div class="hx-change"><span class="hx-change-field">${escHtml(r.field)}</span><span class="hx-change-before">${escHtml(r.before) || '<em>nothing</em>'}</span><span class="hx-change-arrow" aria-hidden="true">→</span><span class="hx-change-after">${escHtml(r.after) || '<em>nothing</em>'}</span></div>`
|
|
174
174
|
: `<div class="hx-change"><span class="hx-change-field">${escHtml(r.field)}</span><span class="hx-change-after">${escHtml(r.after)}</span></div>`)).join('');
|
|
175
|
-
return `<div class="hx-sec hx-proposal-sec hx-proposal-sec--${escHtml(item.mark)}" data-proposal-mark="${escHtml(item.mark)}">
|
|
175
|
+
return `<div class="hx-sec hx-proposal-sec hx-proposal-sec--${escHtml(item.mark)}" data-proposal-mark="${escHtml(item.mark)}" data-corn="section">
|
|
176
176
|
<strong class="hx-strong"><span class="hx-mark-dot hx-mark-dot--${escHtml(item.mark)}"></span>${escHtml(item.mark === 'edit' ? `${item.editOp === 'removed' ? 'Removed' : 'Added'} by your edit` : `${MARK_WORDS[item.mark] || item.mark} by this proposal`)}</strong>
|
|
177
177
|
${item.why ? `<div class="hx-why">${escHtml(item.why)}</div>` : ''}
|
|
178
178
|
${body}
|
package/explorer/proposal.js
CHANGED
|
@@ -282,10 +282,10 @@ function renderChanges() {
|
|
|
282
282
|
const rows = [];
|
|
283
283
|
for (const mark of [...MARKS, 'edit']) {
|
|
284
284
|
for (const n of state.nodes.filter((x) => x.mark === mark)) {
|
|
285
|
-
rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="node" data-key="${escHtml(n.id)}"><span class="hx-mark-dot hx-mark-dot--${mark}"></span><span class="hx-change-what">${escHtml(MARK_WORDS[mark])}</span><span class="hx-name">${escHtml(n.label)}</span><span class="hx-faint">${escHtml(n.type)}</span></button>`);
|
|
285
|
+
rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="node" data-key="${escHtml(n.id)}" data-corn="row"><span class="hx-mark-dot hx-mark-dot--${mark}"></span><span class="hx-change-what">${escHtml(MARK_WORDS[mark])}</span><span class="hx-name">${escHtml(n.label)}</span><span class="hx-faint">${escHtml(n.type)}</span></button>`);
|
|
286
286
|
}
|
|
287
287
|
for (const e of state.edges.filter((x) => x.mark === mark && said.has(edgeKey(x)))) {
|
|
288
|
-
rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="edge" data-key="${escHtml(edgeKey(e))}"><span class="hx-mark-dot hx-mark-dot--${mark}"></span><span class="hx-change-what">${escHtml(MARK_WORDS[mark])}</span><span class="hx-name">${escHtml(nameOf(e.from))} → ${escHtml(nameOf(e.to))}</span><span class="hx-faint">${escHtml(e.kind || 'ownership')}</span></button>`);
|
|
288
|
+
rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="edge" data-key="${escHtml(edgeKey(e))}" data-corn="row"><span class="hx-mark-dot hx-mark-dot--${mark}"></span><span class="hx-change-what">${escHtml(MARK_WORDS[mark])}</span><span class="hx-name">${escHtml(nameOf(e.from))} → ${escHtml(nameOf(e.to))}</span><span class="hx-faint">${escHtml(e.kind || 'ownership')}</span></button>`);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
list.innerHTML = rows.join('') || '<p class="hx-faint">This proposal changes nothing on the map.</p>';
|
|
@@ -350,13 +350,13 @@ export function proposalRowHtml(entry, current) {
|
|
|
350
350
|
const meta = [`<span class="hx-proposal-where">${escHtml(where(entry))}</span>`];
|
|
351
351
|
if (entry.spec) meta.push(`<span>spec ${escHtml(entry.spec)}</span>`);
|
|
352
352
|
if (entry.error) {
|
|
353
|
-
return `<div class="hx-proposal-item is-broken">${head}<span class="hx-proposal-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-proposal-meta">${meta.join('')}</span></div>`;
|
|
353
|
+
return `<div class="hx-proposal-item is-broken" data-corn="row">${head}<span class="hx-proposal-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-proposal-meta">${meta.join('')}</span></div>`;
|
|
354
354
|
}
|
|
355
355
|
if (entry.counts) meta.push(`<span>${escHtml(chipText(entry.counts))}</span>`);
|
|
356
356
|
const reviewed = reviewWords(entry.review, Date.now()); // "Approved 3 minutes ago", from the listing
|
|
357
357
|
if (reviewed) meta.push(`<span class="hx-proposal-reviewed">${escHtml(reviewed)}</span>`);
|
|
358
358
|
if (entry.errors) meta.push(`<span class="hx-warn">${escHtml(plural(entry.errors, 'problem'))}</span>`);
|
|
359
|
-
return `<button type="button" class="hx-proposal-item${mine ? ' is-current' : ''}" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}">${head}${entry.summary ? `<span class="hx-proposal-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-proposal-meta">${meta.join('')}</span></button>`;
|
|
359
|
+
return `<button type="button" class="hx-proposal-item${mine ? ' is-current' : ''}" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}" data-corn="row">${head}${entry.summary ? `<span class="hx-proposal-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-proposal-meta">${meta.join('')}</span></button>`;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
function renderMenu(loading = false) {
|
package/explorer/renderer.js
CHANGED
|
@@ -41,6 +41,7 @@ export function rendererPreference(search) {
|
|
|
41
41
|
function addStandIn(canvas) {
|
|
42
42
|
const standIn = canvas.ownerDocument.createElement('canvas');
|
|
43
43
|
standIn.className = 'hx-overlay';
|
|
44
|
+
standIn.setAttribute('data-corn', 'map-overlay');
|
|
44
45
|
standIn.setAttribute('aria-hidden', 'true');
|
|
45
46
|
canvas.after(standIn);
|
|
46
47
|
return standIn;
|
|
@@ -55,7 +55,7 @@ function paint() {
|
|
|
55
55
|
else {
|
|
56
56
|
list.innerHTML = ui.tokens.map((t) => {
|
|
57
57
|
const line = tokenLine(t, now());
|
|
58
|
-
return `<li class="hx-tokens-item" data-state="${line.state}"><span class="hx-tokens-label">${escHtml(line.label)}</span> <span class="hx-tokens-meta hx-faint">${escHtml(line.status)} · ${escHtml(line.used)}</span> ${line.canRevoke ? `<button type="button" class="hx-btn hx-btn--quiet" data-revoke="${escHtml(String(line.id))}" aria-label="Revoke ${escHtml(line.label)}"${ui.busy ? ' disabled' : ''}>Revoke</button>` : ''}</li>`;
|
|
58
|
+
return `<li class="hx-tokens-item" data-state="${line.state}" data-corn="row"><span class="hx-tokens-label">${escHtml(line.label)}</span> <span class="hx-tokens-meta hx-faint">${escHtml(line.status)} · ${escHtml(line.used)}</span> ${line.canRevoke ? `<button type="button" class="hx-btn hx-btn--quiet" data-revoke="${escHtml(String(line.id))}" aria-label="Revoke ${escHtml(line.label)}"${ui.busy ? ' disabled' : ''} data-corn-kind="danger">Revoke</button>` : ''}</li>`;
|
|
59
59
|
}).join('');
|
|
60
60
|
}
|
|
61
61
|
const intro = $('tokens-intro');
|
|
@@ -64,6 +64,7 @@ function paint() {
|
|
|
64
64
|
msg.hidden = !ui.message;
|
|
65
65
|
msg.textContent = ui.message ? ui.message.text : '';
|
|
66
66
|
msg.classList.toggle('hx-forge-msg--bad', !!ui.message && !ui.message.ok);
|
|
67
|
+
if (ui.message && !ui.message.ok) msg.dataset.cornState = 'failure'; else delete msg.dataset.cornState;
|
|
67
68
|
$('tokens-make').disabled = ui.busy;
|
|
68
69
|
}
|
|
69
70
|
|
package/explorer/review.js
CHANGED
|
@@ -60,12 +60,13 @@ function mount() {
|
|
|
60
60
|
root = document.createElement('div');
|
|
61
61
|
root.id = 'review';
|
|
62
62
|
root.className = 'hx-review';
|
|
63
|
+
root.dataset.corn = 'review-bar';
|
|
63
64
|
root.setAttribute('aria-label', 'Approve or send back');
|
|
64
65
|
root.innerHTML = `
|
|
65
66
|
<label class="hx-review-label" for="review-note">Note for the drafting agent</label>
|
|
66
67
|
<textarea id="review-note" class="hx-review-note" rows="2" maxlength="20000" placeholder="What should change? Needed to send it back, optional to approve."></textarea>
|
|
67
68
|
<div class="hx-review-row">
|
|
68
|
-
<button type="button" class="hx-btn hx-btn--approve" data-review="approved" title="Sign this proposal off">Approve</button>
|
|
69
|
+
<button type="button" class="hx-btn hx-btn--approve" data-review="approved" title="Sign this proposal off" data-corn-kind="approve">Approve</button>
|
|
69
70
|
<button type="button" class="hx-btn" data-review="notes" title="Send it back to the drafting agent with the note and your edits">Send back</button>
|
|
70
71
|
<span class="hx-review-status" data-review-status role="status"></span>
|
|
71
72
|
</div>
|
package/explorer/runs-map.js
CHANGED
|
@@ -108,6 +108,7 @@ export function syncRunOverlay(scene, camera) {
|
|
|
108
108
|
el.className = `hx-run-mark hx-run-mark--${kind}`;
|
|
109
109
|
el.dataset.node = node.id;
|
|
110
110
|
el.dataset.kind = kind;
|
|
111
|
+
el.dataset.corn = 'run-mark';
|
|
111
112
|
el.innerHTML = `<span class="hx-run-ring"></span>${kind === 'collision' ? `<span class="hx-run-tag"><span class="hx-run-sign">⚠</span> ${collisionTag(runs.length)}</span>` : ''}`;
|
|
112
113
|
layer.append(el);
|
|
113
114
|
marks.set(key, el);
|
package/explorer/runs-view.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { relativeTime } from './review-model.js';
|
|
12
12
|
import { runTone, canRetry, aboutWords, statusWords, statusWhy, runMeta, canStop, canAnswer, groupRuns, compareTitle, limitRows, checksWords, timelineWords, nodeLabels, collisionWords, answerWords } from './runs-model.js';
|
|
13
|
+
import { cornStateAttr } from './corn-state.js';
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -84,8 +85,8 @@ function answerHtml(ctx, run) {
|
|
|
84
85
|
const reply = ctx.replies && ctx.replies.get(run.runId) || '';
|
|
85
86
|
return `${run.answer ? answeredHtml(ctx, run) : ''}<div class="hx-run-actions" role="group" aria-label="Answer run ${id}">
|
|
86
87
|
<button type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="Continue run ${id}"${off}>Continue</button>
|
|
87
|
-
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="Stop run ${id}"${off}>Stop</button></div>
|
|
88
|
-
<label class="hx-forge-field">Reply to run ${id}<input type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
|
|
88
|
+
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="Stop run ${id}"${off} data-corn-kind="danger">Stop</button></div>
|
|
89
|
+
<label class="hx-forge-field" data-corn="field">Reply to run ${id}<input type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
|
|
89
90
|
<div class="hx-run-actions"><button type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="Send reply to run ${id}"${off}>Reply</button></div>`;
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -103,14 +104,14 @@ export function runHtml(ctx, run, all) {
|
|
|
103
104
|
const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
|
|
104
105
|
const answering = canAnswer(run);
|
|
105
106
|
const retry = canRetry(run) ? `<button type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="Start again on run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>Start again</button>` : '';
|
|
106
|
-
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="Stop run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>Stop</button>` : '';
|
|
107
|
+
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="Stop run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''} data-corn-kind="danger">Stop</button>` : '';
|
|
107
108
|
const names = nodeLabels(run.nodes, ctx.nodes);
|
|
108
109
|
const collision = collisionWords(run, all, ctx.nodes);
|
|
109
110
|
const limits = limitRows(run);
|
|
110
111
|
const count = (run.timeline || []).length;
|
|
111
112
|
const links = linksHtml(ctx, run);
|
|
112
|
-
return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}" tabindex="-1">
|
|
113
|
-
<div class="hx-run-head"><span class="hx-forge-state hx-forge-state--${tone}">${ctx.esc(statusWords(run))}</span> <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>
|
|
113
|
+
return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}" tabindex="-1" data-corn="run"${cornStateAttr(run.status)}>
|
|
114
|
+
<div class="hx-run-head"><span class="hx-forge-state hx-forge-state--${tone}" data-corn="state-pill"${cornStateAttr(run.status)}>${ctx.esc(statusWords(run))}</span> <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>
|
|
114
115
|
${collision ? `<p class="hx-run-collide"><span aria-hidden="true">⚠</span> ${ctx.esc(collision)}</p>` : ''}
|
|
115
116
|
<p class="hx-forge-meta">${ctx.esc(runMeta(run, ctx.now))}</p>${why ? `<p class="hx-forge-why hx-faint">${ctx.esc(why)}</p>` : ''}${note}
|
|
116
117
|
<dl class="hx-run-limits" aria-label="Limits and what the runner reported">${limits.length ? limits.map((r) => `<dt>${ctx.esc(r.name)}</dt><dd>limit: ${ctx.esc(r.limit)}; reported: ${ctx.esc(r.reported)}</dd>`).join('') : '<dt>Limits</dt><dd>none asked, nothing reported</dd>'}</dl>
|
package/explorer/scenario-ui.js
CHANGED
|
@@ -180,18 +180,19 @@ function showBar(speed) {
|
|
|
180
180
|
if (!stage) return;
|
|
181
181
|
bar = document.createElement('div');
|
|
182
182
|
bar.className = 'hx-player glass';
|
|
183
|
+
bar.dataset.corn = 'scenario-player';
|
|
183
184
|
bar.setAttribute('role', 'region');
|
|
184
185
|
bar.setAttribute('aria-label', 'Scenario player');
|
|
185
186
|
bar.innerHTML = `
|
|
186
187
|
<div class="hx-player-head">
|
|
187
188
|
<span class="hx-player-title"></span>
|
|
188
189
|
<select class="hx-player-speed" data-action="scenario-speed" aria-label="Time for each step" title="Time for each step">${SPEED_CHOICES.map((c) => `<option value="${c.value}">${c.label}</option>`).join('')}</select>
|
|
189
|
-
<button type="button" class="hx-close" data-action="scenario-close" aria-label="Close the scenario">✕</button>
|
|
190
|
+
<button type="button" class="hx-close" data-action="scenario-close" aria-label="Close the scenario" data-corn-kind="icon">✕</button>
|
|
190
191
|
</div>
|
|
191
192
|
<p class="hx-player-text" aria-live="polite"><span class="hx-player-count"></span> · <span class="hx-player-step"></span></p>
|
|
192
193
|
<div class="hx-player-controls">
|
|
193
194
|
<button type="button" class="hx-btn" data-action="scenario-prev">◀ Previous</button>
|
|
194
|
-
<button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle"></button>
|
|
195
|
+
<button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle" data-corn-kind="primary"></button>
|
|
195
196
|
<button type="button" class="hx-btn" data-action="scenario-next">Next ▶</button>
|
|
196
197
|
</div>
|
|
197
198
|
<div class="hx-player-track" aria-hidden="true"><span class="hx-player-fill"></span></div>`;
|
|
@@ -326,6 +327,7 @@ export function refreshList() {
|
|
|
326
327
|
const button = document.createElement('button');
|
|
327
328
|
button.type = 'button';
|
|
328
329
|
button.className = 'hx-scenarios-item';
|
|
330
|
+
button.dataset.corn = 'row';
|
|
329
331
|
button.dataset.scenario = s.id;
|
|
330
332
|
const steps = (s.steps || []).length;
|
|
331
333
|
button.textContent = `${s.title} · ${steps} ${steps === 1 ? 'step' : 'steps'}`;
|
package/explorer/sheets.js
CHANGED
|
@@ -108,6 +108,7 @@ export function registerSheet(id, el) {
|
|
|
108
108
|
handle = document.createElement('button');
|
|
109
109
|
handle.type = 'button';
|
|
110
110
|
handle.className = 'hx-sheet-handle';
|
|
111
|
+
handle.dataset.corn = 'sheet-handle';
|
|
111
112
|
handle.innerHTML = '<span></span>';
|
|
112
113
|
el.prepend(handle);
|
|
113
114
|
}
|
package/explorer/whatif.js
CHANGED
|
@@ -227,6 +227,7 @@ function mount() {
|
|
|
227
227
|
root = document.createElement('div');
|
|
228
228
|
root.id = 'whatif';
|
|
229
229
|
root.className = 'hx-whatif';
|
|
230
|
+
root.dataset.corn = 'whatif';
|
|
230
231
|
root.setAttribute('aria-label', 'Try a change');
|
|
231
232
|
root.innerHTML = `
|
|
232
233
|
<div class="hx-whatif-row" role="toolbar" aria-label="Try a change">
|
|
@@ -238,8 +239,8 @@ function mount() {
|
|
|
238
239
|
<button type="button" class="hx-btn" data-whatif="steps" aria-expanded="false" title="Add, reword, reorder or delete the steps of a scenario">Steps</button>
|
|
239
240
|
</div>
|
|
240
241
|
<p class="hx-whatif-hint" data-hint hidden>Drag from one node to another. Escape cancels.</p>
|
|
241
|
-
<p class="hx-whatif-msg" data-msg="toolbar" role="status" hidden></p>
|
|
242
|
-
<p class="hx-whatif-notice" data-notice role="status" hidden></p>
|
|
242
|
+
<p class="hx-whatif-msg" data-msg="toolbar" role="status" hidden data-corn="message"></p>
|
|
243
|
+
<p class="hx-whatif-notice" data-notice role="status" hidden data-corn="notice"></p>
|
|
243
244
|
<div class="hx-whatif-panel" data-panel="confirm" hidden></div>
|
|
244
245
|
<div class="hx-whatif-panel" data-panel="form" hidden></div>
|
|
245
246
|
<div class="hx-whatif-panel" data-panel="edits" hidden></div>
|
|
@@ -316,7 +317,7 @@ function paintConfirm() {
|
|
|
316
317
|
<div class="hx-whatif-actions">
|
|
317
318
|
<button type="button" class="hx-btn hx-btn--active" data-whatif="close-keep">Close and keep my edits</button>
|
|
318
319
|
<button type="button" class="hx-btn" data-whatif="close-discard">Close and throw them away</button>
|
|
319
|
-
<button type="button" class="hx-btn hx-btn--quiet" data-whatif="close-cancel">Keep editing</button>
|
|
320
|
+
<button type="button" class="hx-btn hx-btn--quiet" data-whatif="close-cancel" data-corn-kind="quiet">Keep editing</button>
|
|
320
321
|
</div>`;
|
|
321
322
|
}
|
|
322
323
|
|
|
@@ -350,16 +351,16 @@ function paintForm() {
|
|
|
350
351
|
box.innerHTML = `
|
|
351
352
|
<form class="hx-whatif-form" data-form="node" autocomplete="off">
|
|
352
353
|
<strong class="hx-strong">Add a node</strong>
|
|
353
|
-
<label class="hx-whatif-field">Type <select name="nodeType">${typeOptions('page')}</select></label>
|
|
354
|
-
<label class="hx-whatif-field">Label <input name="label" class="hx-whatif-input" placeholder="/meals" required></label>
|
|
355
|
-
<label class="hx-whatif-field">Parent <select name="parent">${options.join('')}</select></label>
|
|
354
|
+
<label class="hx-whatif-field" data-corn="field">Type <select name="nodeType">${typeOptions('page')}</select></label>
|
|
355
|
+
<label class="hx-whatif-field" data-corn="field">Label <input name="label" class="hx-whatif-input" placeholder="/meals" required></label>
|
|
356
|
+
<label class="hx-whatif-field" data-corn="field">Parent <select name="parent">${options.join('')}</select></label>
|
|
356
357
|
<p class="hx-faint hx-whatif-help">Click a node on the map to make it the parent. A page label starts with a slash, like /meals.</p>
|
|
357
|
-
<label class="hx-whatif-field">Description <input name="desc" class="hx-whatif-input" placeholder="Optional"></label>
|
|
358
|
+
<label class="hx-whatif-field" data-corn="field">Description <input name="desc" class="hx-whatif-input" placeholder="Optional"></label>
|
|
358
359
|
<div class="hx-whatif-actions">
|
|
359
360
|
<button type="submit" class="hx-btn hx-btn--active">Add node</button>
|
|
360
|
-
<button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form">Cancel</button>
|
|
361
|
+
<button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form" data-corn-kind="quiet">Cancel</button>
|
|
361
362
|
</div>
|
|
362
|
-
<p class="hx-whatif-msg" data-msg="form" role="alert" hidden></p>
|
|
363
|
+
<p class="hx-whatif-msg" data-msg="form" role="alert" hidden data-corn="message"></p>
|
|
363
364
|
</form>`;
|
|
364
365
|
box.querySelector('[name="nodeType"]').value = 'page';
|
|
365
366
|
box.querySelector('[name="parent"]').value = parent;
|
|
@@ -372,14 +373,14 @@ function paintForm() {
|
|
|
372
373
|
<form class="hx-whatif-form" data-form="edge" autocomplete="off">
|
|
373
374
|
<strong class="hx-strong">Draw an edge</strong>
|
|
374
375
|
<p class="hx-whatif-pair"><span class="hx-name">${escHtml(nameOf(form.from))}</span> → <span class="hx-name">${escHtml(nameOf(form.to))}</span></p>
|
|
375
|
-
<label class="hx-whatif-field">Kind <select name="kind">${M.EDGE_CHOICES.map((c) => `<option value="${escHtml(c.value)}"${c.value === suggested ? ' selected' : ''}>${escHtml(c.label)}</option>`).join('')}</select></label>
|
|
376
|
-
<label class="hx-whatif-field" data-flow-field hidden>Flow <select name="flow">${M.FLOW_KINDS.map((f) => `<option value="${escHtml(f)}">${escHtml(f)}</option>`).join('')}</select></label>
|
|
377
|
-
<label class="hx-whatif-field">Label <input name="label" class="hx-whatif-input" placeholder="Optional"></label>
|
|
376
|
+
<label class="hx-whatif-field" data-corn="field">Kind <select name="kind">${M.EDGE_CHOICES.map((c) => `<option value="${escHtml(c.value)}"${c.value === suggested ? ' selected' : ''}>${escHtml(c.label)}</option>`).join('')}</select></label>
|
|
377
|
+
<label class="hx-whatif-field" data-flow-field hidden data-corn="field">Flow <select name="flow">${M.FLOW_KINDS.map((f) => `<option value="${escHtml(f)}">${escHtml(f)}</option>`).join('')}</select></label>
|
|
378
|
+
<label class="hx-whatif-field" data-corn="field">Label <input name="label" class="hx-whatif-input" placeholder="Optional"></label>
|
|
378
379
|
<div class="hx-whatif-actions">
|
|
379
380
|
<button type="submit" class="hx-btn hx-btn--active">Add edge</button>
|
|
380
|
-
<button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form">Cancel</button>
|
|
381
|
+
<button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form" data-corn-kind="quiet">Cancel</button>
|
|
381
382
|
</div>
|
|
382
|
-
<p class="hx-whatif-msg" data-msg="form" role="alert" hidden></p>
|
|
383
|
+
<p class="hx-whatif-msg" data-msg="form" role="alert" hidden data-corn="message"></p>
|
|
383
384
|
</form>`;
|
|
384
385
|
box.querySelector('[name="kind"]').value = suggested;
|
|
385
386
|
syncFlowField();
|
|
@@ -439,7 +440,7 @@ function paintEdits() {
|
|
|
439
440
|
};
|
|
440
441
|
const rows = state.whatIf.edits.map((edit, i) => `<li class="hx-whatif-edit"><span class="hx-mark-dot hx-mark-dot--edit"></span><span class="hx-whatif-edit-text">${escHtml(M.describeEdit(edit, words))}</span><button type="button" class="hx-textbtn" data-whatif="remove-edit" data-index="${i}" aria-label="Remove this edit: ${escHtml(M.describeEdit(edit, words))}">Remove</button></li>`);
|
|
441
442
|
box.innerHTML = rows.length
|
|
442
|
-
? `<ol class="hx-whatif-list">${rows.join('')}</ol><p class="hx-whatif-msg" data-msg="edits" role="status" hidden></p>`
|
|
443
|
+
? `<ol class="hx-whatif-list">${rows.join('')}</ol><p class="hx-whatif-msg" data-msg="edits" role="status" hidden data-corn="message"></p>`
|
|
443
444
|
: '<p class="hx-faint">No edits yet. Add a node, draw an edge or change a step, and it appears here.</p>';
|
|
444
445
|
paintMessages();
|
|
445
446
|
}
|
|
@@ -474,17 +475,17 @@ function paintSteps() {
|
|
|
474
475
|
box.innerHTML = `
|
|
475
476
|
<div class="hx-whatif-form">
|
|
476
477
|
<div class="hx-whatif-actions">
|
|
477
|
-
<label class="hx-whatif-field">Scenario <select data-scenario-select>${scenarios.map((s) => `<option value="${escHtml(s.id)}"${s.id === ui.scenarioId ? ' selected' : ''}>${escHtml(s.title)}</option>`).join('')}<option value="${NEW}"${ui.scenarioId === NEW ? ' selected' : ''}>New scenario…</option></select></label>
|
|
478
|
+
<label class="hx-whatif-field" data-corn="field">Scenario <select data-scenario-select>${scenarios.map((s) => `<option value="${escHtml(s.id)}"${s.id === ui.scenarioId ? ' selected' : ''}>${escHtml(s.title)}</option>`).join('')}<option value="${NEW}"${ui.scenarioId === NEW ? ' selected' : ''}>New scenario…</option></select></label>
|
|
478
479
|
${scenario ? '<button type="button" class="hx-btn" data-whatif="play-scenario">Play</button>' : ''}
|
|
479
480
|
</div>
|
|
480
481
|
${rows.length ? `<ol class="hx-whatif-list hx-whatif-steps">${rows.join('')}</ol>` : '<p class="hx-faint">No steps yet.</p>'}
|
|
481
482
|
<form class="hx-whatif-addstep" data-form="step" autocomplete="off">
|
|
482
|
-
${ui.scenarioId === NEW ? `<label class="hx-whatif-field">Title <input name="title" class="hx-whatif-input" placeholder="Add a meal" value="${escHtml(ui.titleDraft)}"></label>` : ''}
|
|
483
|
-
<label class="hx-whatif-field">New step <input name="text" class="hx-whatif-input" placeholder="What happens here?" value="${escHtml(ui.stepDraft)}"></label>
|
|
483
|
+
${ui.scenarioId === NEW ? `<label class="hx-whatif-field" data-corn="field">Title <input name="title" class="hx-whatif-input" placeholder="Add a meal" value="${escHtml(ui.titleDraft)}"></label>` : ''}
|
|
484
|
+
<label class="hx-whatif-field" data-corn="field">New step <input name="text" class="hx-whatif-input" placeholder="What happens here?" value="${escHtml(ui.stepDraft)}"></label>
|
|
484
485
|
<button type="submit" class="hx-btn hx-btn--active" data-step-add>Add step</button>
|
|
485
486
|
<span class="hx-faint hx-whatif-pointing" data-step-target></span>
|
|
486
487
|
</form>
|
|
487
|
-
<p class="hx-whatif-msg" data-msg="steps" role="alert" hidden></p>
|
|
488
|
+
<p class="hx-whatif-msg" data-msg="steps" role="alert" hidden data-corn="message"></p>
|
|
488
489
|
</div>`;
|
|
489
490
|
paintStepTarget();
|
|
490
491
|
paintMessages();
|
|
@@ -543,7 +544,7 @@ function edgeToHtml(n) {
|
|
|
543
544
|
.slice(0, EDGE_TO_MAX);
|
|
544
545
|
if (!others.length) return '';
|
|
545
546
|
return `<div class="hx-whatif-addstep hx-whatif-edgeto">
|
|
546
|
-
<label class="hx-whatif-field">Edge to <select data-edge-to>${others.map((o) => `<option value="${escHtml(o.id)}">${escHtml(o.label)} (${escHtml(o.type)})</option>`).join('')}</select></label>
|
|
547
|
+
<label class="hx-whatif-field" data-corn="field">Edge to <select data-edge-to>${others.map((o) => `<option value="${escHtml(o.id)}">${escHtml(o.label)} (${escHtml(o.type)})</option>`).join('')}</select></label>
|
|
547
548
|
<button type="button" class="hx-btn" data-whatif="edge-to" data-from="${escHtml(n.id)}" title="Draw an edge from this node to the one picked, without dragging">Draw an edge</button>
|
|
548
549
|
</div>`;
|
|
549
550
|
}
|
|
@@ -555,7 +556,7 @@ function paintDrawer() {
|
|
|
555
556
|
box.hidden = !open;
|
|
556
557
|
if (!open) { box.innerHTML = ''; return; }
|
|
557
558
|
|
|
558
|
-
const message = '<p class="hx-whatif-msg" data-msg="drawer" role="alert" hidden></p>';
|
|
559
|
+
const message = '<p class="hx-whatif-msg" data-msg="drawer" role="alert" hidden data-corn="message"></p>';
|
|
559
560
|
const title = '<h3 class="hx-block-title">Try a change</h3>';
|
|
560
561
|
if (state.selectedEdge) {
|
|
561
562
|
const e = state.selectedEdge;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.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)",
|
package/server/server.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
* GET /cornfield/theme.css, /cornfield/theme/<name>.css
|
|
20
20
|
* the stylesheets the config's `theme` names (css, names): those files only, as text/css
|
|
21
21
|
* GET /cornfield/theme/assets/<path> an image or font beside the theme files (png, svg, webp, gif, avif, woff2, woff; 1 MB each)
|
|
22
|
+
* GET /cornfield/brand/<key>.<ext> a brand image the config's `brand` names (logo, wordmark, favicon; svg or png, 512 KB each): those files only
|
|
23
|
+
* GET /manifest.webmanifest the web app manifest: the repo's title, or built from `brand` when the config sets one
|
|
22
24
|
* GET /api/forge/… issues, pull requests, their files and checks, release notes: read from the forge (server/forge-routes.js)
|
|
23
25
|
* POST /api/forge/pulls/<n>/merge|rerun land a green pull request, re-run a failed check (server/forge-actions.js)
|
|
24
26
|
* POST /api/forge/issues/<n>/spec, /pulls/<n>/build the pipeline's steps (server/pipeline.js, server/forge-actions.js)
|
|
@@ -53,6 +55,7 @@ import { createHash, randomBytes } from 'node:crypto';
|
|
|
53
55
|
import { fileURLToPath } from 'node:url';
|
|
54
56
|
import { browserSources, BUILTIN_SOURCES, parseDuration, specPollMs, triggersOf, DEFAULTS, hookWants, ideaLabel, runnerQuietAfterMs } from '../core/config.js';
|
|
55
57
|
import { CLOUD_FILE } from '../core/cloud.js';
|
|
58
|
+
import { BRAND_SVG_CSP, MANIFEST_PATH, appNameOf, brandAssetFile, brandImages, clientBrand, colorOf, manifestOf } from '../core/brand.js';
|
|
56
59
|
import { MAX_THEME_ASSET_BYTES, MAX_THEME_BYTES, THEME_ASSET_PREFIX, THEME_NAME, THEME_SVG_CSP, clientTheme, cssProblems, fontOrigins, fontUrl, themeAssetFile, themeAssetPath } from '../core/theme.js';
|
|
57
60
|
import { decodePath, inside, notFound, sendFile } from './files.js';
|
|
58
61
|
import { serveProposals } from './proposals.js';
|
|
@@ -126,9 +129,9 @@ function themeHead(theme) {
|
|
|
126
129
|
const u = fontUrl(f);
|
|
127
130
|
if (u) out.push(`<link rel="stylesheet" href="${escapeHtml(u.href)}" referrerpolicy="no-referrer" />`);
|
|
128
131
|
}
|
|
129
|
-
if (theme.css) out.push('<link rel="stylesheet" href="/cornfield/theme.css" data-
|
|
132
|
+
if (theme.css) out.push('<link rel="stylesheet" href="/cornfield/theme.css" data-corn-theme="css" />');
|
|
130
133
|
const { names, fallback } = themeNamesOf(theme);
|
|
131
|
-
if (names.length) out.push(`<link rel="stylesheet" id="cf-theme-name-css"${fallback ? ` href="/cornfield/theme/${fallback}.css"` : ''} data-
|
|
134
|
+
if (names.length) out.push(`<link rel="stylesheet" id="cf-theme-name-css"${fallback ? ` href="/cornfield/theme/${fallback}.css"` : ''} data-corn-theme="name" />`);
|
|
132
135
|
return out.join('\n ');
|
|
133
136
|
}
|
|
134
137
|
|
|
@@ -184,6 +187,57 @@ function sendThemeAsset(req, res, config, reqPath) {
|
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
|
|
190
|
+
/** The brand images the config names, by the path they are served at: `Map<'/cornfield/brand/<key>.<ext>', rel>` */
|
|
191
|
+
function brandFilesOf(config) {
|
|
192
|
+
return new Map(brandImages(config.brand).map((i) => [i.url, i.rel]));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The `<head>` lines of a brand: the favicon, the manifest (always, so any cornfield installs as an app; fetched with the sign-in
|
|
197
|
+
* cookie, since the page is behind it) and the tab colour
|
|
198
|
+
*/
|
|
199
|
+
function brandHead(brand) {
|
|
200
|
+
const out = [];
|
|
201
|
+
const favicon = brandImages(brand).find((i) => i.key === 'favicon');
|
|
202
|
+
if (favicon) out.push(`<link rel="icon" href="${escapeHtml(favicon.url)}" type="${favicon.type}" />`);
|
|
203
|
+
out.push(`<link rel="manifest" href="${MANIFEST_PATH}" crossorigin="use-credentials" />`);
|
|
204
|
+
const color = colorOf(brand && brand.color);
|
|
205
|
+
if (color) out.push(`<meta name="theme-color" content="${escapeHtml(color)}" />`);
|
|
206
|
+
return out.join('\n ');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The page's title: the repo's, then the app's name (cornfield, unless the brand names the app) */
|
|
210
|
+
function titleOf(config) {
|
|
211
|
+
const app = appNameOf(config.brand);
|
|
212
|
+
return app && app === config.title ? app : `${config.title} · ${app || 'cornfield'}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Serves one brand image: only a file the config names (`brand.logo`, `wordmark`, `favicon`), a plain svg or png file whose real path
|
|
217
|
+
* is inside the repo, whose bytes match its extension, at most 512 KB (core/brand.js `brandAssetFile`, the check `cornfield validate`
|
|
218
|
+
* makes). nosniff always; an SVG gets a policy of its own and is never inlined into the page.
|
|
219
|
+
*/
|
|
220
|
+
function sendBrand(req, res, config, rel, reqPath) {
|
|
221
|
+
try {
|
|
222
|
+
const found = brandAssetFile(config.root, rel);
|
|
223
|
+
if ('problem' in found) return notFound(res, reqPath);
|
|
224
|
+
res.writeHead(200, {
|
|
225
|
+
'Content-Type': found.type, 'Content-Length': found.body.length, 'Cache-Control': 'no-cache', 'X-Content-Type-Options': 'nosniff',
|
|
226
|
+
...(found.type === 'image/svg+xml' ? { 'Content-Security-Policy': BRAND_SVG_CSP } : {}),
|
|
227
|
+
});
|
|
228
|
+
return res.end(req.method === 'HEAD' ? undefined : found.body);
|
|
229
|
+
} catch {
|
|
230
|
+
return notFound(res, reqPath);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The web app manifest (core/brand.js `manifestOf`), as application/manifest+json: served with or without a brand */
|
|
235
|
+
function sendManifest(req, res, config) {
|
|
236
|
+
const body = JSON.stringify(manifestOf(config.brand, config.title, (rel) => brandAssetFile(config.root, rel)));
|
|
237
|
+
res.writeHead(200, { 'Content-Type': 'application/manifest+json; charset=utf-8', 'Cache-Control': 'no-cache', 'X-Content-Type-Options': 'nosniff' });
|
|
238
|
+
return res.end(req.method === 'HEAD' ? undefined : body);
|
|
239
|
+
}
|
|
240
|
+
|
|
187
241
|
/** The browser modules the config names from the repo: each one's folder may be served (its .js files only) */
|
|
188
242
|
function repoModuleDirs(config) {
|
|
189
243
|
const dirs = [];
|
|
@@ -208,6 +262,8 @@ export function clientConfig(config, signIn = false) {
|
|
|
208
262
|
links: config.links || [],
|
|
209
263
|
// The theme's names and default, never a file's path (docs/config.md#theme)
|
|
210
264
|
theme: clientTheme(config.theme),
|
|
265
|
+
// The brand's image URLs and name, never a file's path (docs/config.md#brand)
|
|
266
|
+
brand: clientBrand(config.brand, PKG.homepage),
|
|
211
267
|
forge: config.forge ? { type: config.forge.type, url: config.forge.url || (config.forge.type === 'github' ? 'https://github.com' : null), repo: config.forge.repo, mergeMethod: config.forge.mergeMethod || 'merge', ...(config.approveLands ? { approveLands: true } : {}) } : null,
|
|
212
268
|
// Threads (docs/threads.md): the idea label, or false when `threads: false` turns the Threads tab off
|
|
213
269
|
threads: config.threads === false ? false : { label: ideaLabel(config) },
|
|
@@ -258,6 +314,7 @@ export function createCornfieldServer(config, opts = {}) {
|
|
|
258
314
|
const theme = config.theme || {};
|
|
259
315
|
const csp = cspOf(importMap, theme);
|
|
260
316
|
const themeFile = themeFilesOf(config);
|
|
317
|
+
const brandFile = brandFilesOf(config);
|
|
261
318
|
const repoModules = repoModuleDirs(config);
|
|
262
319
|
const publicHost = config.publicUrl ? new URL(config.publicUrl).hostname : null;
|
|
263
320
|
const where = { root, proposals: config.proposals, worktrees: config.worktrees, worktreeMaxAgeDays: config.worktreeMaxAgeDays, topology: config.topology, dataDir: config.dataDir, publicHost };
|
|
@@ -312,7 +369,8 @@ export function createCornfieldServer(config, opts = {}) {
|
|
|
312
369
|
.replace('<!--@importmap-->', importMap ? `<script type="importmap">${importMap}</script>` : '')
|
|
313
370
|
.replace('<html lang="en">', () => themeHtmlTag(theme))
|
|
314
371
|
.replace('<!--@theme-->', () => themeHead(theme)) // a function, so a `$` in a font URL is not a replacement pattern
|
|
315
|
-
.replace(
|
|
372
|
+
.replace('<!--@brand-->', () => brandHead(config.brand))
|
|
373
|
+
.replace(/<title>[^<]*<\/title>/, () => `<title>${escapeHtml(titleOf(config))}</title>`); // a function: a `$` in a name is not a pattern
|
|
316
374
|
return html;
|
|
317
375
|
};
|
|
318
376
|
|
|
@@ -407,6 +465,8 @@ export function createCornfieldServer(config, opts = {}) {
|
|
|
407
465
|
}
|
|
408
466
|
if (themeFile.has(reqPath)) return sendTheme(req, res, config, themeFile.get(reqPath), reqPath);
|
|
409
467
|
if (reqPath.startsWith(THEME_ASSET_PREFIX)) return sendThemeAsset(req, res, config, reqPath);
|
|
468
|
+
if (brandFile.has(reqPath)) return sendBrand(req, res, config, brandFile.get(reqPath), reqPath);
|
|
469
|
+
if (reqPath === MANIFEST_PATH) return sendManifest(req, res, config);
|
|
410
470
|
if (reqPath === '/cornfield/config.json') return sendJson(res, 200, clientConfig(config, signedIn));
|
|
411
471
|
if (reqPath === '/topology.json') {
|
|
412
472
|
const file = inside(root, config.topology);
|