cornfield 0.27.0 → 0.29.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/config.js +5 -0
- package/core/strings.js +118 -0
- package/explorer/explorer.css +64 -17
- package/explorer/forge-panel.js +11 -10
- package/explorer/index.html +53 -37
- package/explorer/main.js +1 -1
- package/explorer/panels.js +3 -2
- package/explorer/plugins.js +6 -2
- package/explorer/proposal-model.js +13 -0
- package/explorer/proposal.js +68 -7
- package/explorer/review.js +69 -17
- package/explorer/runs-view.js +6 -5
- package/explorer/scenario-ui.js +26 -7
- package/explorer/sheets.js +1 -1
- package/explorer/strings.js +68 -0
- package/explorer/view.js +2 -1
- package/explorer/whatif.js +20 -3
- package/package.json +1 -1
- package/server/server.js +4 -1
package/explorer/review.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/review
|
|
3
3
|
*
|
|
4
|
-
* Approving a proposal and sending it back: the two buttons
|
|
5
|
-
* click does. "Approve"
|
|
4
|
+
* Approving a proposal and sending it back: the two buttons on the proposal toolbar (index.html), the note that opens
|
|
5
|
+
* under it, and what a click does. "Approve" takes no note. "Send back" opens the note field (focus moves to it; Cancel
|
|
6
|
+
* closes it and gives focus back to Send back); the button then reads "Send back with this note" and a note is needed.
|
|
7
|
+
* Both put the maintainer's what-if
|
|
6
8
|
* edits (`getEdits()`, whatif.js) in the review, which the server posts as a comment on the spec PR, as the
|
|
7
9
|
* signed-in maintainer (`PUT /proposals/<slug>/review`, server/proposals.js, server/reviews.js). The agent drafting
|
|
8
10
|
* the spec reads it (`cornfield review <slug>`) and folds the edits into the proposal. Only a proposal of a spec PR
|
|
@@ -22,10 +24,12 @@
|
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
import { state } from './state.js';
|
|
27
|
+
import { expandSheet, isPhone } from './sheets.js';
|
|
25
28
|
import { hooks } from './proposal.js';
|
|
26
29
|
import { refreshMockups } from './mockups.js';
|
|
27
30
|
import { getEdits, clearEdits } from './whatif.js';
|
|
28
31
|
import { reviewWords, sendBackProblem, reviewBody, editsHint, isReviewable, NOT_ON_A_PR } from './review-model.js';
|
|
32
|
+
import { t } from './strings.js';
|
|
29
33
|
|
|
30
34
|
const $ = (id) => document.getElementById(id);
|
|
31
35
|
|
|
@@ -37,6 +41,7 @@ const ui = {
|
|
|
37
41
|
reviewable: false, // whether it is on a spec PR
|
|
38
42
|
review: null, // { verdict, at } | null: the last review of it
|
|
39
43
|
busy: false,
|
|
44
|
+
noting: false, // the note field is open (Send back was pressed)
|
|
40
45
|
message: '', // an inline refusal or failure
|
|
41
46
|
hint: '', // what happens to the edits
|
|
42
47
|
};
|
|
@@ -51,8 +56,10 @@ const slugOf = () => state.proposalSlug || null;
|
|
|
51
56
|
const keyOf = () => (state.proposal && slugOf() ? `${state.proposalSource || ''}/${slugOf()}` : null);
|
|
52
57
|
const reviewUrl = () => `/proposals/${encodeURIComponent(slugOf())}/review${state.proposalSource ? `?source=${encodeURIComponent(state.proposalSource)}` : ''}`;
|
|
53
58
|
const q = (sel) => (root ? root.querySelector(sel) : null);
|
|
59
|
+
/** The toolbar's own buttons: Send back and Approve (index.html) */
|
|
60
|
+
const button = (verdict) => document.querySelector(`#proposal-bar [data-review="${verdict}"]`);
|
|
54
61
|
|
|
55
|
-
/** The
|
|
62
|
+
/** The status line, the note field and the lines under them; added to the toolbar once, just before Send back and Approve, so Tab goes from the note to Cancel and then to "Send back with this note" (on a phone it sits under the counts, above the two buttons; from 768px CSS gives it a row under the toolbar) */
|
|
56
63
|
function mount() {
|
|
57
64
|
const body = $('proposal-body');
|
|
58
65
|
if (!body) return null;
|
|
@@ -61,21 +68,27 @@ function mount() {
|
|
|
61
68
|
root.id = 'review';
|
|
62
69
|
root.className = 'hx-review';
|
|
63
70
|
root.dataset.corn = 'review-bar';
|
|
64
|
-
root.setAttribute('aria-label', 'Approve or send back');
|
|
65
71
|
root.innerHTML = `
|
|
66
|
-
<
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
+
<p class="hx-review-status" data-review-status role="status" hidden></p>
|
|
73
|
+
<div class="hx-review-form" id="review-form" data-review-form hidden>
|
|
74
|
+
<label class="hx-review-label" for="review-note"></label>
|
|
75
|
+
<textarea id="review-note" class="hx-review-note" rows="2" maxlength="20000"></textarea>
|
|
76
|
+
<div class="hx-review-row">
|
|
77
|
+
<button type="button" class="hx-btn hx-btn--quiet" data-review-cancel data-corn-kind="quiet">Cancel</button>
|
|
78
|
+
</div>
|
|
72
79
|
</div>
|
|
73
80
|
<p class="hx-review-msg" data-review-msg role="alert" hidden></p>
|
|
74
81
|
<p class="hx-review-line" data-review-hint role="status" hidden></p>
|
|
75
82
|
`;
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
// The words are set as text and attributes, never parsed as HTML (a brand's `strings`, explorer/strings.js)
|
|
84
|
+
q('.hx-review-label').textContent = t('reviewNoteLabel');
|
|
85
|
+
q('#review-note').setAttribute('placeholder', t('reviewNotePlaceholder'));
|
|
86
|
+
const actions = body.querySelector('.hx-proposal-actions');
|
|
87
|
+
if (actions) actions.before(root); else body.prepend(root);
|
|
88
|
+
const bar = $('proposal-bar');
|
|
89
|
+
(bar || root).addEventListener('click', onClick);
|
|
78
90
|
root.addEventListener('input', () => { if (ui.message) { ui.message = ''; paint(); } });
|
|
91
|
+
root.addEventListener('keydown', (e) => { if (e.key === 'Escape' && ui.noting) { e.stopPropagation(); closeNote(); } });
|
|
79
92
|
}
|
|
80
93
|
return root;
|
|
81
94
|
}
|
|
@@ -86,7 +99,17 @@ function paint() {
|
|
|
86
99
|
const status = q('[data-review-status]');
|
|
87
100
|
status.textContent = reviewWords(ui.review, now());
|
|
88
101
|
status.hidden = !status.textContent;
|
|
89
|
-
for (const btn of
|
|
102
|
+
for (const btn of document.querySelectorAll('#proposal-bar [data-review]')) btn.disabled = ui.busy || !ui.reviewable;
|
|
103
|
+
const approve = button('approved');
|
|
104
|
+
if (approve) approve.textContent = t('approve');
|
|
105
|
+
const sendBack = button('notes');
|
|
106
|
+
if (sendBack) {
|
|
107
|
+
sendBack.textContent = ui.noting ? t('sendBackWithNote') : t('sendBack');
|
|
108
|
+
sendBack.setAttribute('aria-expanded', String(ui.noting));
|
|
109
|
+
sendBack.setAttribute('aria-controls', 'review-form');
|
|
110
|
+
}
|
|
111
|
+
q('[data-review-form]').hidden = !ui.noting;
|
|
112
|
+
q('[data-review-cancel]').disabled = ui.busy;
|
|
90
113
|
q('#review-note').disabled = !ui.reviewable;
|
|
91
114
|
for (const [sel, text] of [['[data-review-msg]', ui.message], ['[data-review-hint]', ui.reviewable ? ui.hint : ui.key ? NOT_ON_A_PR : '']]) {
|
|
92
115
|
const el = q(sel);
|
|
@@ -95,6 +118,25 @@ function paint() {
|
|
|
95
118
|
}
|
|
96
119
|
}
|
|
97
120
|
|
|
121
|
+
/** Send back was pressed: the note field opens and takes focus (on a phone the sheet opens to hold it) */
|
|
122
|
+
function openNote() {
|
|
123
|
+
ui.noting = true;
|
|
124
|
+
ui.message = '';
|
|
125
|
+
paint();
|
|
126
|
+
if (isPhone()) expandSheet('proposal');
|
|
127
|
+
q('#review-note').focus();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Cancel: the field closes, what was typed goes, and focus goes back to Send back */
|
|
131
|
+
function closeNote() {
|
|
132
|
+
ui.noting = false;
|
|
133
|
+
ui.message = '';
|
|
134
|
+
q('#review-note').value = '';
|
|
135
|
+
paint();
|
|
136
|
+
const sendBack = button('notes');
|
|
137
|
+
if (sendBack) sendBack.focus();
|
|
138
|
+
}
|
|
139
|
+
|
|
98
140
|
/** hooks.bar: the bar was drawn. Mount, and when it is another proposal than the one shown, start again for it. */
|
|
99
141
|
function onBar(open) {
|
|
100
142
|
if (!mount()) return;
|
|
@@ -105,6 +147,7 @@ function onBar(open) {
|
|
|
105
147
|
ui.reviewable = !!key && isReviewable(state.proposalSource);
|
|
106
148
|
ui.review = null;
|
|
107
149
|
ui.busy = false;
|
|
150
|
+
ui.noting = false;
|
|
108
151
|
ui.message = ui.hint = '';
|
|
109
152
|
const note = q('#review-note');
|
|
110
153
|
if (note) note.value = '';
|
|
@@ -125,8 +168,12 @@ async function loadReview(key) {
|
|
|
125
168
|
}
|
|
126
169
|
|
|
127
170
|
function onClick(e) {
|
|
128
|
-
|
|
129
|
-
if (
|
|
171
|
+
if (ui.busy || !e.target.closest) return;
|
|
172
|
+
if (e.target.closest('[data-review-cancel]')) { closeNote(); return; }
|
|
173
|
+
const btn = e.target.closest('[data-review]');
|
|
174
|
+
if (!btn || btn.disabled) return;
|
|
175
|
+
if (btn.dataset.review === 'notes' && !ui.noting) openNote(); // the first press opens the field, the second sends
|
|
176
|
+
else sendReview(btn.dataset.review);
|
|
130
177
|
}
|
|
131
178
|
|
|
132
179
|
/**
|
|
@@ -137,13 +184,15 @@ function onClick(e) {
|
|
|
137
184
|
export async function sendReview(verdict) {
|
|
138
185
|
if (!state.proposal || !slugOf() || !mount() || !ui.reviewable) return false;
|
|
139
186
|
const noteEl = q('#review-note');
|
|
140
|
-
const note = noteEl.value;
|
|
187
|
+
const note = verdict === 'notes' ? noteEl.value : ''; // an approval takes no note
|
|
141
188
|
ui.hint = '';
|
|
142
189
|
if (verdict === 'notes') {
|
|
143
190
|
const problem = sendBackProblem(note);
|
|
144
191
|
if (problem) {
|
|
145
192
|
ui.message = problem;
|
|
193
|
+
ui.noting = true; // the refusal is about the note: show it
|
|
146
194
|
paint();
|
|
195
|
+
if (isPhone()) expandSheet('proposal');
|
|
147
196
|
noteEl.focus();
|
|
148
197
|
return false;
|
|
149
198
|
}
|
|
@@ -171,7 +220,10 @@ export async function sendReview(verdict) {
|
|
|
171
220
|
ui.review = { verdict: saved.verdict, at: saved.at };
|
|
172
221
|
ui.hint = editsHint(verdict, body.edits.length);
|
|
173
222
|
noteEl.value = '';
|
|
223
|
+
const wasNoting = ui.noting;
|
|
224
|
+
ui.noting = false;
|
|
174
225
|
paint();
|
|
226
|
+
if (wasNoting && verdict === 'notes') { const sendBack = button('notes'); if (sendBack) sendBack.focus(); }
|
|
175
227
|
refreshMockups(); // an approval covers the screens as they are now; a send back leaves them not reviewed
|
|
176
228
|
if (verdict === 'notes') clearEdits(); // the edits went with the note; an approval keeps them, they are in the review
|
|
177
229
|
return true;
|
|
@@ -202,5 +254,5 @@ export function resetReviewForTests(clock = () => Date.now()) {
|
|
|
202
254
|
wired = false;
|
|
203
255
|
root = null;
|
|
204
256
|
now = clock;
|
|
205
|
-
Object.assign(ui, { key: null, reviewable: false, review: null, busy: false, message: '', hint: '' });
|
|
257
|
+
Object.assign(ui, { key: null, reviewable: false, review: null, busy: false, noting: false, message: '', hint: '' });
|
|
206
258
|
}
|
package/explorer/runs-view.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
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
13
|
import { cornStateAttr } from './corn-state.js';
|
|
14
|
+
import { t } from './strings.js';
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -84,10 +85,10 @@ function answerHtml(ctx, run) {
|
|
|
84
85
|
const off = ctx.busy ? ' disabled' : '';
|
|
85
86
|
const reply = ctx.replies && ctx.replies.get(run.runId) || '';
|
|
86
87
|
return `${run.answer ? answeredHtml(ctx, run) : ''}<div class="hx-run-actions" role="group" aria-label="Answer run ${id}">
|
|
87
|
-
<button type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="
|
|
88
|
-
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="
|
|
88
|
+
<button type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="${ctx.esc(t('continueRun'))} run ${id}"${off}>${ctx.esc(t('continueRun'))}</button>
|
|
89
|
+
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="${ctx.esc(t('stop'))} run ${id}"${off} data-corn-kind="danger">${ctx.esc(t('stop'))}</button></div>
|
|
89
90
|
<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>
|
|
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="
|
|
91
|
+
<div class="hx-run-actions"><button type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="${ctx.esc(t('reply'))} to run ${id}"${off}>${ctx.esc(t('reply'))}</button></div>`;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
/** The totals as plain lines (see `totalsLines`), escaped; '' when there are none */
|
|
@@ -103,8 +104,8 @@ export function runHtml(ctx, run, all) {
|
|
|
103
104
|
const why = statusWhy(run);
|
|
104
105
|
const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
|
|
105
106
|
const answering = canAnswer(run);
|
|
106
|
-
const retry = canRetry(run) ? `<button type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="
|
|
107
|
-
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="
|
|
107
|
+
const retry = canRetry(run) ? `<button type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="${ctx.esc(t('startAgain'))} on run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>${ctx.esc(t('startAgain'))}</button>` : '';
|
|
108
|
+
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="${ctx.esc(t('stop'))} run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''} data-corn-kind="danger">${ctx.esc(t('stop'))}</button>` : '';
|
|
108
109
|
const names = nodeLabels(run.nodes, ctx.nodes);
|
|
109
110
|
const collision = collisionWords(run, all, ctx.nodes);
|
|
110
111
|
const limits = limitRows(run);
|
package/explorer/scenario-ui.js
CHANGED
|
@@ -308,21 +308,39 @@ function mountList() {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
|
|
311
|
+
const wiredPlay = new WeakSet();
|
|
312
|
+
|
|
313
|
+
/** The toolbar's Play button: shown while the open proposal has scenarios and none plays; with one it plays it, with several it opens the list */
|
|
314
|
+
function paintPlay(show) {
|
|
315
|
+
const btn = document.getElementById('proposal-play');
|
|
316
|
+
if (!btn) return;
|
|
317
|
+
btn.hidden = !show;
|
|
318
|
+
// with one scenario Play plays it, so it expands nothing
|
|
319
|
+
if (proposalScenarios().length > 1) btn.setAttribute('aria-expanded', String(!!list && !list.hidden)); else btn.removeAttribute('aria-expanded');
|
|
320
|
+
if (wiredPlay.has(btn)) return;
|
|
321
|
+
wiredPlay.add(btn);
|
|
322
|
+
btn.addEventListener('click', () => {
|
|
323
|
+
const scenarios = proposalScenarios();
|
|
324
|
+
if (scenarios.length === 1) playScenario(scenarios[0]);
|
|
325
|
+
else if (list) { list.hidden = !list.hidden; btn.setAttribute('aria-expanded', String(!list.hidden)); }
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Shows or hides the Play button and its list to match the open proposal's scenarios (and hides them while one plays: the player is the control then) */
|
|
312
330
|
export function refreshList() {
|
|
313
331
|
const stage = $stage();
|
|
314
332
|
const scenarios = proposalScenarios();
|
|
315
333
|
const show = !!stage && scenarios.length > 0 && !player;
|
|
316
|
-
if (!show) { if (list) { list.remove(); list = null; } return; }
|
|
334
|
+
if (!show) { if (list) { list.remove(); list = null; } paintPlay(false); return; }
|
|
317
335
|
const key = scenarios.map((s) => `${s.id}\u0000${s.title}\u0000${(s.steps || []).length}`).join('\u0001');
|
|
318
|
-
if (list && list.dataset.key === key) { mountList(); return; }
|
|
336
|
+
if (list && list.dataset.key === key) { mountList(); paintPlay(true); return; }
|
|
337
|
+
const wasOpen = !!list && !list.hidden;
|
|
319
338
|
if (list) list.remove();
|
|
320
|
-
list = document.createElement('
|
|
339
|
+
list = document.createElement('div');
|
|
340
|
+
list.id = 'proposal-scenarios';
|
|
321
341
|
list.className = 'hx-scenarios glass';
|
|
322
342
|
list.dataset.key = key;
|
|
323
|
-
|
|
324
|
-
summary.textContent = `Scenarios · ${scenarios.length}`;
|
|
325
|
-
list.appendChild(summary);
|
|
343
|
+
list.hidden = !!document.getElementById('proposal-play') && (!wasOpen || scenarios.length < 2); // behind Play when the toolbar has one
|
|
326
344
|
scenarios.forEach((s) => {
|
|
327
345
|
const button = document.createElement('button');
|
|
328
346
|
button.type = 'button';
|
|
@@ -340,6 +358,7 @@ export function refreshList() {
|
|
|
340
358
|
if (scenario) playScenario(scenario);
|
|
341
359
|
});
|
|
342
360
|
mountList();
|
|
361
|
+
paintPlay(true);
|
|
343
362
|
}
|
|
344
363
|
|
|
345
364
|
// ---------------------------------------------------------------------------
|
package/explorer/sheets.js
CHANGED
|
@@ -165,7 +165,7 @@ function peekClick(id, e) {
|
|
|
165
165
|
if (!isPhone() || model.isExpanded(id)) return;
|
|
166
166
|
const target = e.target;
|
|
167
167
|
if (target.closest && target.closest('.hx-sheet-handle')) return; // the handle's own listener
|
|
168
|
-
if (target.closest && target.closest('select, input, textarea')) return; // the speed menu
|
|
168
|
+
if (target.closest && target.closest('select, input, textarea, [data-peek-ok]')) return; // the speed menu, and the proposal's Send back, Approve and mode switcher, work from the peek
|
|
169
169
|
const action = target.closest && target.closest('[data-action]');
|
|
170
170
|
if (action && /close/.test(action.dataset.action)) return;
|
|
171
171
|
e.preventDefault();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/strings
|
|
3
|
+
*
|
|
4
|
+
* The words a repo may say in its own voice (core/strings.js is the table; `strings` in cornfield.config.js the overrides, which
|
|
5
|
+
* `/cornfield/config.json` carries). Every overridable label is read through `t(key)`; the static markup in index.html marks what
|
|
6
|
+
* to replace with `data-corn-string` attributes, which `applyStrings` fills once the config is in.
|
|
7
|
+
*
|
|
8
|
+
* data-corn-string="key" the element's text
|
|
9
|
+
* data-corn-string-aria-label="key" its aria-label
|
|
10
|
+
* data-corn-string-placeholder="key" its placeholder
|
|
11
|
+
*
|
|
12
|
+
* The rule for accessible names: a control's name is its visible label. When a key is overridden the visible text and the
|
|
13
|
+
* aria-label carry the same words, and where a name adds a fixed target ("Stop run 7") only the label part is replaced
|
|
14
|
+
* ("Halt run 7"). So a screen reader says what is on the screen.
|
|
15
|
+
*
|
|
16
|
+
* Values are only ever set through textContent and attributes, never as HTML, and a value that fails core/strings.js
|
|
17
|
+
* `stringProblem` (not text, a line break, too long) is ignored here as well, whatever the server sent.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { STRINGS, isStringKey, stringProblem } from '../core/strings.js';
|
|
21
|
+
|
|
22
|
+
/** The overrides in force: key -> text */
|
|
23
|
+
let overrides = {};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Takes the overrides the config carries (`config.strings`). Anything that is not a known key with good text is left out.
|
|
27
|
+
* @param {unknown} strings
|
|
28
|
+
*/
|
|
29
|
+
export function setStrings(strings) {
|
|
30
|
+
overrides = {};
|
|
31
|
+
if (!strings || typeof strings !== 'object' || Array.isArray(strings)) return;
|
|
32
|
+
for (const [key, value] of Object.entries(strings)) if (isStringKey(key) && !stringProblem(value)) overrides[key] = value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether the config overrides this key */
|
|
36
|
+
export const isOverridden = (key) => Object.hasOwn(overrides, key);
|
|
37
|
+
|
|
38
|
+
/** The words for a key: the override, else the default. A key that is not in the table gives the key itself (a test keeps the code to the table). */
|
|
39
|
+
export function t(key) {
|
|
40
|
+
if (Object.hasOwn(overrides, key)) return overrides[key];
|
|
41
|
+
return isStringKey(key) ? STRINGS[key] : String(key);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const TARGETS = [
|
|
45
|
+
['data-corn-string', (el, text) => { el.textContent = text; }],
|
|
46
|
+
['data-corn-string-aria-label', (el, text) => el.setAttribute('aria-label', text)],
|
|
47
|
+
['data-corn-string-placeholder', (el, text) => el.setAttribute('placeholder', text)],
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Puts the overrides in the static markup. Only an overridden key touches its element, so what index.html says is what shows
|
|
52
|
+
* without one.
|
|
53
|
+
* @param {ParentNode} root
|
|
54
|
+
*/
|
|
55
|
+
export function applyStrings(root) {
|
|
56
|
+
if (!root || typeof root.querySelectorAll !== 'function') return;
|
|
57
|
+
for (const [attr, set] of TARGETS) {
|
|
58
|
+
for (const el of root.querySelectorAll(`[${attr}]`)) {
|
|
59
|
+
const key = el.getAttribute(attr);
|
|
60
|
+
if (isOverridden(key)) set(el, overrides[key]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** For tests: forget the overrides */
|
|
66
|
+
export function resetStringsForTests() {
|
|
67
|
+
overrides = {};
|
|
68
|
+
}
|
package/explorer/view.js
CHANGED
|
@@ -15,6 +15,7 @@ import { clearScenario } from './scenario-ui.js';
|
|
|
15
15
|
import { measureParams } from './bench.js';
|
|
16
16
|
import { mergeLive, placeLiveNodes } from './live-model.js';
|
|
17
17
|
import { applyHouseLayout } from './house-model.js';
|
|
18
|
+
import { t } from './strings.js';
|
|
18
19
|
|
|
19
20
|
const $ = (id) => document.getElementById(id);
|
|
20
21
|
|
|
@@ -166,5 +167,5 @@ export function syncViewUi() {
|
|
|
166
167
|
const note = $('layers-preset-note');
|
|
167
168
|
if (note) note.hidden = !preset;
|
|
168
169
|
const badge = $('instruction-badge-text');
|
|
169
|
-
if (badge) badge.textContent = preset ? '
|
|
170
|
+
if (badge) badge.textContent = preset ? t('hintDataFlow') : (state.isFreeform ? t('hintDrag') : t('hintInspect'));
|
|
170
171
|
}
|
package/explorer/whatif.js
CHANGED
|
@@ -32,6 +32,7 @@ const $ = (id) => document.getElementById(id);
|
|
|
32
32
|
|
|
33
33
|
/** What the controls are showing; none of it is saved */
|
|
34
34
|
const ui = {
|
|
35
|
+
editing: false, // the Edit button is on: the controls are showing
|
|
35
36
|
panel: null, // 'edits' | 'steps' | null: the list that is open under the toolbar
|
|
36
37
|
form: null, // { kind: 'node' } | { kind: 'edge', from, to } | null: the small form that is open
|
|
37
38
|
drawing: false, // "Draw an edge" is on
|
|
@@ -127,7 +128,7 @@ hooks.bar = () => renderUi();
|
|
|
127
128
|
function resetUi() {
|
|
128
129
|
endGesture();
|
|
129
130
|
setDrawing(false);
|
|
130
|
-
Object.assign(ui, { panel: null, form: null, confirm: false, closing: false, scenarioId: null, stepDraft: '', titleDraft: '', notice: '', messages: {}, lastSelected: null });
|
|
131
|
+
Object.assign(ui, { editing: false, panel: null, form: null, confirm: false, closing: false, scenarioId: null, stepDraft: '', titleDraft: '', notice: '', messages: {}, lastSelected: null });
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
// ---------------------------------------------------------------------------
|
|
@@ -245,7 +246,10 @@ function mount() {
|
|
|
245
246
|
<div class="hx-whatif-panel" data-panel="form" hidden></div>
|
|
246
247
|
<div class="hx-whatif-panel" data-panel="edits" hidden></div>
|
|
247
248
|
<div class="hx-whatif-panel" data-panel="steps" hidden></div>`;
|
|
249
|
+
root.hidden = true;
|
|
248
250
|
body.appendChild(root);
|
|
251
|
+
const edit = $('proposal-edit');
|
|
252
|
+
if (edit) edit.addEventListener('click', () => setEditing(!ui.editing));
|
|
249
253
|
root.addEventListener('click', onClick);
|
|
250
254
|
root.addEventListener('submit', onSubmit);
|
|
251
255
|
root.addEventListener('change', onChange);
|
|
@@ -260,7 +264,13 @@ const q = (sel) => (root ? root.querySelector(sel) : null);
|
|
|
260
264
|
function renderUi() {
|
|
261
265
|
const open = !!state.proposal;
|
|
262
266
|
if (!mount()) return;
|
|
263
|
-
root.hidden = !open;
|
|
267
|
+
root.hidden = !open || !(ui.editing || ui.confirm || ui.notice); // the confirm on Close and the notice about dropped edits are seen whatever Edit says
|
|
268
|
+
const edit = $('proposal-edit');
|
|
269
|
+
if (edit) {
|
|
270
|
+
edit.setAttribute('aria-expanded', String(ui.editing));
|
|
271
|
+
edit.classList.toggle('hx-btn--active', ui.editing);
|
|
272
|
+
edit.textContent = state.whatIf.edits.length ? `Edit · ${state.whatIf.edits.length}` : 'Edit';
|
|
273
|
+
}
|
|
264
274
|
if (!open) { paintDrawer(); return; }
|
|
265
275
|
|
|
266
276
|
const wi = state.whatIf;
|
|
@@ -291,6 +301,13 @@ function renderUi() {
|
|
|
291
301
|
paintDrawer();
|
|
292
302
|
}
|
|
293
303
|
|
|
304
|
+
/** Edit: shows or hides the controls; hiding them ends a drawing and closes the form, the edits stay */
|
|
305
|
+
function setEditing(on) {
|
|
306
|
+
ui.editing = on;
|
|
307
|
+
if (!on) { setDrawing(false); ui.form = null; ui.panel = null; }
|
|
308
|
+
renderUi();
|
|
309
|
+
}
|
|
310
|
+
|
|
294
311
|
/** Puts each inline refusal next to its control (and hides the ones with nothing to say) */
|
|
295
312
|
function paintMessages() {
|
|
296
313
|
if (!root) return;
|
|
@@ -903,6 +920,6 @@ export function resetWhatIfForTests() {
|
|
|
903
920
|
loadedKey = null;
|
|
904
921
|
saveWarned = false;
|
|
905
922
|
listeners.clear();
|
|
906
|
-
Object.assign(ui, { panel: null, form: null, drawing: false, confirm: false, closing: false, scenarioId: null, stepDraft: '', titleDraft: '', notice: '', messages: {}, recentParents: [], lastSelected: null });
|
|
923
|
+
Object.assign(ui, { editing: false, panel: null, form: null, drawing: false, confirm: false, closing: false, scenarioId: null, stepDraft: '', titleDraft: '', notice: '', messages: {}, recentParents: [], lastSelected: null });
|
|
907
924
|
state.whatIf = M.emptyWhatIf();
|
|
908
925
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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
|
@@ -56,6 +56,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
56
56
|
import { browserSources, BUILTIN_SOURCES, parseDuration, specPollMs, triggersOf, DEFAULTS, hookWants, ideaLabel, runnerQuietAfterMs } from '../core/config.js';
|
|
57
57
|
import { CLOUD_FILE } from '../core/cloud.js';
|
|
58
58
|
import { BRAND_SVG_CSP, MANIFEST_PATH, appNameOf, brandAssetFile, brandImages, clientBrand, colorOf, manifestOf } from '../core/brand.js';
|
|
59
|
+
import { clientStrings } from '../core/strings.js';
|
|
59
60
|
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';
|
|
60
61
|
import { decodePath, inside, notFound, sendFile } from './files.js';
|
|
61
62
|
import { serveProposals } from './proposals.js';
|
|
@@ -78,7 +79,7 @@ import { createTriggers } from './triggers.js';
|
|
|
78
79
|
export const CORNFIELD_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
79
80
|
const EXPLORER_DIR = path.join(CORNFIELD_DIR, 'explorer');
|
|
80
81
|
/** The pure core modules the explorer imports (no Node built-ins, no files): the only ones of core/ served */
|
|
81
|
-
export const BROWSER_CORE = ['schema.js', 'proposal.js', 'personas.js', 'cloud.js', 'text.js', 'mentions.js', 'color.js'];
|
|
82
|
+
export const BROWSER_CORE = ['schema.js', 'proposal.js', 'personas.js', 'cloud.js', 'text.js', 'mentions.js', 'color.js', 'strings.js'];
|
|
82
83
|
/** cornfield's own browser sources, by request path */
|
|
83
84
|
const BROWSER_PLUGINS = new Map(Object.values(BUILTIN_SOURCES).map((p) => [p, path.join(CORNFIELD_DIR, p)]));
|
|
84
85
|
const PKG = JSON.parse(fs.readFileSync(path.join(CORNFIELD_DIR, 'package.json'), 'utf8'));
|
|
@@ -264,6 +265,8 @@ export function clientConfig(config, signIn = false) {
|
|
|
264
265
|
theme: clientTheme(config.theme),
|
|
265
266
|
// The brand's image URLs and name, never a file's path (docs/config.md#brand)
|
|
266
267
|
brand: clientBrand(config.brand, PKG.homepage),
|
|
268
|
+
// Only the labels the config overrides, as text (core/strings.js); the defaults are in the browser
|
|
269
|
+
strings: clientStrings(config.strings),
|
|
267
270
|
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,
|
|
268
271
|
// Threads (docs/threads.md): the idea label, or false when `threads: false` turns the Threads tab off
|
|
269
272
|
threads: config.threads === false ? false : { label: ideaLabel(config) },
|