@popcorn245/cornfield 0.28.0 → 0.30.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.
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * @module explorer/review
3
3
  *
4
- * Approving a proposal and sending it back: the two buttons and the note under the proposal bar, and what a
5
- * click does. "Approve" (a note is optional) and "Send back" (a note is needed) both put the maintainer's what-if
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,6 +24,7 @@
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';
@@ -38,6 +41,7 @@ const ui = {
38
41
  reviewable: false, // whether it is on a spec PR
39
42
  review: null, // { verdict, at } | null: the last review of it
40
43
  busy: false,
44
+ noting: false, // the note field is open (Send back was pressed)
41
45
  message: '', // an inline refusal or failure
42
46
  hint: '', // what happens to the edits
43
47
  };
@@ -52,8 +56,10 @@ const slugOf = () => state.proposalSlug || null;
52
56
  const keyOf = () => (state.proposal && slugOf() ? `${state.proposalSource || ''}/${slugOf()}` : null);
53
57
  const reviewUrl = () => `/proposals/${encodeURIComponent(slugOf())}/review${state.proposalSource ? `?source=${encodeURIComponent(state.proposalSource)}` : ''}`;
54
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}"]`);
55
61
 
56
- /** The note box, the two buttons, and the lines under them; added to the bar once */
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) */
57
63
  function mount() {
58
64
  const body = $('proposal-body');
59
65
  if (!body) return null;
@@ -62,14 +68,14 @@ function mount() {
62
68
  root.id = 'review';
63
69
  root.className = 'hx-review';
64
70
  root.dataset.corn = 'review-bar';
65
- root.setAttribute('aria-label', `${t('approve')} or ${t('sendBack')}`);
66
71
  root.innerHTML = `
67
- <label class="hx-review-label" for="review-note"></label>
68
- <textarea id="review-note" class="hx-review-note" rows="2" maxlength="20000"></textarea>
69
- <div class="hx-review-row">
70
- <button type="button" class="hx-btn hx-btn--approve" data-review="approved" title="Sign this proposal off" data-corn-kind="approve"></button>
71
- <button type="button" class="hx-btn" data-review="notes" title="Send it back to the drafting agent with the note and your edits"></button>
72
- <span class="hx-review-status" data-review-status role="status"></span>
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>
73
79
  </div>
74
80
  <p class="hx-review-msg" data-review-msg role="alert" hidden></p>
75
81
  <p class="hx-review-line" data-review-hint role="status" hidden></p>
@@ -77,11 +83,12 @@ function mount() {
77
83
  // The words are set as text and attributes, never parsed as HTML (a brand's `strings`, explorer/strings.js)
78
84
  q('.hx-review-label').textContent = t('reviewNoteLabel');
79
85
  q('#review-note').setAttribute('placeholder', t('reviewNotePlaceholder'));
80
- q('[data-review="approved"]').textContent = t('approve');
81
- q('[data-review="notes"]').textContent = t('sendBack');
82
- body.appendChild(root);
83
- root.addEventListener('click', onClick);
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);
84
90
  root.addEventListener('input', () => { if (ui.message) { ui.message = ''; paint(); } });
91
+ root.addEventListener('keydown', (e) => { if (e.key === 'Escape' && ui.noting) { e.stopPropagation(); closeNote(); } });
85
92
  }
86
93
  return root;
87
94
  }
@@ -92,7 +99,17 @@ function paint() {
92
99
  const status = q('[data-review-status]');
93
100
  status.textContent = reviewWords(ui.review, now());
94
101
  status.hidden = !status.textContent;
95
- for (const btn of root.querySelectorAll('[data-review]')) btn.disabled = ui.busy || !ui.reviewable;
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;
96
113
  q('#review-note').disabled = !ui.reviewable;
97
114
  for (const [sel, text] of [['[data-review-msg]', ui.message], ['[data-review-hint]', ui.reviewable ? ui.hint : ui.key ? NOT_ON_A_PR : '']]) {
98
115
  const el = q(sel);
@@ -101,6 +118,25 @@ function paint() {
101
118
  }
102
119
  }
103
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
+
104
140
  /** hooks.bar: the bar was drawn. Mount, and when it is another proposal than the one shown, start again for it. */
105
141
  function onBar(open) {
106
142
  if (!mount()) return;
@@ -111,6 +147,7 @@ function onBar(open) {
111
147
  ui.reviewable = !!key && isReviewable(state.proposalSource);
112
148
  ui.review = null;
113
149
  ui.busy = false;
150
+ ui.noting = false;
114
151
  ui.message = ui.hint = '';
115
152
  const note = q('#review-note');
116
153
  if (note) note.value = '';
@@ -131,8 +168,12 @@ async function loadReview(key) {
131
168
  }
132
169
 
133
170
  function onClick(e) {
134
- const btn = e.target.closest ? e.target.closest('[data-review]') : null;
135
- if (btn && !ui.busy) sendReview(btn.dataset.review);
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);
136
177
  }
137
178
 
138
179
  /**
@@ -143,13 +184,15 @@ function onClick(e) {
143
184
  export async function sendReview(verdict) {
144
185
  if (!state.proposal || !slugOf() || !mount() || !ui.reviewable) return false;
145
186
  const noteEl = q('#review-note');
146
- const note = noteEl.value;
187
+ const note = verdict === 'notes' ? noteEl.value : ''; // an approval takes no note
147
188
  ui.hint = '';
148
189
  if (verdict === 'notes') {
149
190
  const problem = sendBackProblem(note);
150
191
  if (problem) {
151
192
  ui.message = problem;
193
+ ui.noting = true; // the refusal is about the note: show it
152
194
  paint();
195
+ if (isPhone()) expandSheet('proposal');
153
196
  noteEl.focus();
154
197
  return false;
155
198
  }
@@ -177,7 +220,10 @@ export async function sendReview(verdict) {
177
220
  ui.review = { verdict: saved.verdict, at: saved.at };
178
221
  ui.hint = editsHint(verdict, body.edits.length);
179
222
  noteEl.value = '';
223
+ const wasNoting = ui.noting;
224
+ ui.noting = false;
180
225
  paint();
226
+ if (wasNoting && verdict === 'notes') { const sendBack = button('notes'); if (sendBack) sendBack.focus(); }
181
227
  refreshMockups(); // an approval covers the screens as they are now; a send back leaves them not reviewed
182
228
  if (verdict === 'notes') clearEdits(); // the edits went with the note; an approval keeps them, they are in the review
183
229
  return true;
@@ -208,5 +254,5 @@ export function resetReviewForTests(clock = () => Date.now()) {
208
254
  wired = false;
209
255
  root = null;
210
256
  now = clock;
211
- 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: '' });
212
258
  }
@@ -308,21 +308,39 @@ function mountList() {
308
308
  }
309
309
  }
310
310
 
311
- /** Shows or hides the list to match `state.proposal.scenarios` (and hides it while one plays: the bar is the control then) */
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('details');
339
+ list = document.createElement('div');
340
+ list.id = 'proposal-scenarios';
321
341
  list.className = 'hx-scenarios glass';
322
342
  list.dataset.key = key;
323
- const summary = document.createElement('summary');
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
  // ---------------------------------------------------------------------------
@@ -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 works from the peek
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();
package/explorer/state.js CHANGED
@@ -128,7 +128,7 @@ export const state = {
128
128
  /**
129
129
  * Which threads mention which nodes (forge-panel.js, docs/threads.md), for a node's panel: `{ for(nodeId) -> thread[] | null,
130
130
  * ensure(), open(number) }`, or null when threads are off or there is no forge. `for` answers null until the list has been
131
- * read; `ensure` reads it (once) and repaints the panel's "Mentioned in"; `open` shows a thread in the issues and PRs panel.
131
+ * read; `ensure` reads it (once) and repaints the panel's "Threads"; `open` shows a thread in the issues and PRs panel.
132
132
  */
133
133
  threadIndex: null,
134
134
 
@@ -82,6 +82,7 @@
82
82
  --corn-text-md: 13px;
83
83
  --corn-text-base: 14px;
84
84
  --corn-text-lg: 15px;
85
+ --corn-text-xl: 20px;
85
86
 
86
87
  /* Shape */
87
88
  --corn-radius-xs: 3px;
@@ -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;
@@ -518,7 +535,7 @@ function mountDrawerBox() {
518
535
  drawerBox.id = 'whatif-drawer';
519
536
  drawerBox.className = 'hx-block hx-whatif-drawer';
520
537
  drawerBox.hidden = true;
521
- block.parentElement.insertBefore(drawerBox, block);
538
+ block.after(drawerBox); // under the facts, the mockups and the threads: the node comes first, the tools to edit it after
522
539
  drawerBox.addEventListener('click', onClick);
523
540
  return drawerBox;
524
541
  }
@@ -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": "@popcorn245/cornfield",
3
- "version": "0.28.0",
3
+ "version": "0.30.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)",