@popcorn245/cornfield 0.30.0 → 0.32.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.
@@ -192,6 +192,48 @@ export function proposalPanelHtml(item) {
192
192
  </div>`;
193
193
  }
194
194
 
195
+ // ---------------------------------------------------------------------------
196
+ // A proposal as a row of the Work panel's Specs tab
197
+ // ---------------------------------------------------------------------------
198
+
199
+ /** What a listing entry's state pill says: its spec PR's state, or "Local" for a proposal that is only in a checkout or a worktree */
200
+ export const specState = (entry) => (entry.pull ? (entry.pull.draft ? 'Draft' : 'Open') : 'Local');
201
+
202
+ /** Where a listing entry is, as a line of meta: "PR #11", or the checkout or worktree it is in */
203
+ export function specWhere(entry) {
204
+ if (entry.pull) return `PR #${entry.pull.number}`;
205
+ return entry.source === 'checkout' ? 'in the checkout' : `in worktree ${entry.source}`;
206
+ }
207
+
208
+ /**
209
+ * One row: title, a state pill, a line of what it is for, and the meta (spec number, where it is, +added ~changed −removed, scenarios).
210
+ * A proposal that could not be read is a row that says why and opens nothing. Same `open-proposal` action as the Proposals menu's row.
211
+ * @param {{ slug: string, source: string, title?: string, summary?: string, spec?: string, pull?: {number: number, draft?: boolean}, counts?: {added?: number, changed?: number, removed?: number, scenarios?: number}, errors?: number, error?: string }} entry
212
+ * @param {{ current?: {slug: string, source: string} | null }} [opts] the proposal that is open now
213
+ */
214
+ export function specRowHtml(entry, { current = null } = {}) {
215
+ const head = `<span class="hx-forge-title">${escHtml(entry.title || entry.slug)}</span>`;
216
+ if (entry.error) {
217
+ return `<li class="hx-forge-item"><div class="hx-forge-row hx-forge-spec" data-corn="row">${head}<span class="hx-forge-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-forge-meta">${escHtml(specWhere(entry))}</span></div></li>`;
218
+ }
219
+ const state = specState(entry);
220
+ const tone = state === 'Local' ? '' : ` data-corn-state="${state === 'Draft' ? 'draft' : 'open'}"`;
221
+ const c = entry.counts || {};
222
+ const meta = [
223
+ entry.spec ? `<span>spec ${escHtml(entry.spec)}</span>` : '',
224
+ `<span>${escHtml(specWhere(entry))}</span>`,
225
+ c.added ? `<span class="hx-forge-add" title="${c.added} added">+${c.added}</span>` : '',
226
+ c.changed ? `<span class="hx-forge-chg" title="${c.changed} changed">~${c.changed}</span>` : '',
227
+ c.removed ? `<span class="hx-forge-del" title="${c.removed} removed">\u2212${c.removed}</span>` : '',
228
+ c.scenarios ? `<span>${c.scenarios} ${c.scenarios === 1 ? 'scenario' : 'scenarios'}</span>` : '',
229
+ entry.errors ? `<span class="hx-warn">${entry.errors} ${entry.errors === 1 ? 'problem' : 'problems'}</span>` : '',
230
+ ].filter(Boolean).join('');
231
+ const mine = !!current && current.slug === entry.slug && current.source === entry.source;
232
+ return `<li class="hx-forge-item"><button type="button" class="hx-forge-row hx-forge-spec" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}" aria-pressed="${mine}" data-corn="row">`
233
+ + `<span class="hx-forge-line">${head}<span class="hx-forge-state hx-forge-state--${state === 'Draft' ? 'draft' : state === 'Open' ? 'open' : 'neutral'}" data-corn="state-pill"${tone}>${state}</span></span>`
234
+ + `${entry.summary ? `<span class="hx-forge-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-forge-meta hx-forge-facts">${meta}</span></button></li>`;
235
+ }
236
+
195
237
  // ---------------------------------------------------------------------------
196
238
  // Where an added node sits
197
239
  // ---------------------------------------------------------------------------
@@ -53,6 +53,17 @@ let listing = null;
53
53
  let listingProblem = null;
54
54
  /** Why the server left the open spec PRs out of the last listing (the forge could not be asked), or null */
55
55
  let forgeProblem = null;
56
+ /** When the listing was last read (ms), and who wants to hear of a new one (the Work panel's Specs tab, forge-panel.js) */
57
+ let listingAt = 0;
58
+ const listingWatchers = new Set();
59
+
60
+ /** What the server listed last, for the Work panel's Specs tab: the entries (null before the first answer), why the list could not be read, why the spec PRs are missing, and when */
61
+ export const proposalListing = () => ({ entries: listing, problem: listingProblem, forgeProblem, at: listingAt });
62
+ /** Calls `fn` each time the list is read again; returns the way to stop */
63
+ export function onProposalListing(fn) {
64
+ listingWatchers.add(fn);
65
+ return () => listingWatchers.delete(fn);
66
+ }
56
67
 
57
68
  // ---------------------------------------------------------------------------
58
69
  // Loading and closing
@@ -63,7 +74,9 @@ export async function loadProposalList() {
63
74
  try {
64
75
  const res = await fetch('/proposals', { cache: 'no-store' });
65
76
  if (!res.ok) throw new Error(`GET /proposals answered ${res.status}`);
66
- listing = await res.json();
77
+ const body = await res.json();
78
+ if (!Array.isArray(body)) throw new Error('GET /proposals did not answer with a list');
79
+ listing = body;
67
80
  listingProblem = null;
68
81
  const said = res.headers.get('X-Proposals-Forge-Error');
69
82
  forgeProblem = said ? decodeURIComponent(said) : null;
@@ -72,7 +85,9 @@ export async function loadProposalList() {
72
85
  forgeProblem = null;
73
86
  listingProblem = err.message || String(err);
74
87
  }
88
+ listingAt = Date.now();
75
89
  renderMenu();
90
+ for (const fn of listingWatchers) fn();
76
91
  return listing;
77
92
  }
78
93
 
@@ -132,11 +132,6 @@ export function screenToWorld(sx, sy) {
132
132
  return { x: (sx - state.camera.x) / state.camera.zoom, y: (sy - state.camera.y) / state.camera.zoom };
133
133
  }
134
134
 
135
- export function zoomBy(factor) {
136
- state.camera.zoom = Math.max(0.25, Math.min(3.0, state.camera.zoom * factor));
137
- render();
138
- }
139
-
140
135
  // ---------------------------------------------------------------------------
141
136
  // When to draw (frame.js has the rules): on demand, not on a timer
142
137
  // ---------------------------------------------------------------------------
@@ -161,7 +161,8 @@ export function closeTokens({ restoreFocus = true } = {}) {
161
161
  el.hidden = true;
162
162
  document.removeEventListener('focusin', keepFocusIn);
163
163
  $('tokens-btn').setAttribute('aria-expanded', 'false');
164
- if (restoreFocus) $('tokens-btn').focus();
164
+ // The button is in the account menu, which is shut by now: the focus goes to the menu's button then
165
+ if (restoreFocus) ($('tokens-btn').closest('[hidden]') ? $('account-btn') : $('tokens-btn')).focus();
165
166
  }
166
167
 
167
168
  function onClick(e) {
@@ -59,6 +59,21 @@ export function runOnThread(runs, number) {
59
59
  return [...mine.filter((r) => r.open === true).sort(newest), ...mine.filter((r) => r.open !== true).sort(newest)][0];
60
60
  }
61
61
 
62
+ /** The run that made a pull request (the one whose pull request it is), an open one before a finished one, then the newest; null when none did */
63
+ export function runOnPull(runs, number) {
64
+ if (!Array.isArray(runs)) return null;
65
+ const mine = runs.filter((r) => r.pull && r.pull.number === number);
66
+ const newest = (a, b) => Date.parse(b.requestedAt || 0) - Date.parse(a.requestedAt || 0);
67
+ return [...mine.filter((r) => r.open === true).sort(newest), ...mine.filter((r) => r.open !== true).sort(newest)][0] || null;
68
+ }
69
+
70
+ /** A pull request's run in one line: who is running it, its state, how long ago it was asked for, and the cost the runner reported ("bucket-bot · Working · asked 12 min ago · cost 0.84") */
71
+ export function pullRunWords(run, nowMs) {
72
+ const who = (run.report && run.report.by) || (run.pull && run.pull.by) || run.requestedBy;
73
+ const when = relativeTime(run.requestedAt, nowMs);
74
+ return [who, statusWords(run), when && `asked ${when}`, run.report && run.report.cost != null && `cost ${run.report.cost}`].filter(Boolean).join(' · ');
75
+ }
76
+
62
77
  /** What a thread's row says of its run, in a few words: "Run: Working" (more than one run on it: "Run: Working (+1)") */
63
78
  export function threadRunWords(runs, number) {
64
79
  const run = runOnThread(runs, number);
@@ -90,15 +90,6 @@ export function themeChoiceFrom(search, stored) {
90
90
  return { choice: THEME_CHOICES.includes(stored) ? stored : 'system', fromAddress: false };
91
91
  }
92
92
 
93
- /** The choice after `choice` on the toggle: system, light, dark, then system again */
94
- export const nextChoice = (choice) => THEME_CHOICES[(THEME_CHOICES.indexOf(choice) + 1) % THEME_CHOICES.length];
95
-
96
- /** What the toggle says it is set to, in plain words (its label and title) */
97
- export function themeWords(choice, theme) {
98
- if (choice === 'system') return `Theme: follows the system (${theme} now)`;
99
- return `Theme: ${choice}`;
100
- }
101
-
102
93
  // ---------------------------------------------------------------------------
103
94
  // Colour arithmetic
104
95
  // ---------------------------------------------------------------------------
package/explorer/theme.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * decides which theme is on and tells the page:
6
6
  *
7
7
  * - the choice is `system` (the default: `prefers-color-scheme`, followed live), `light` or `dark`;
8
- * the toggle in the header steps through them and keeps the choice in localStorage
8
+ * the System / Dark / Light segment in the account menu sets it and keeps the choice in localStorage
9
9
  * (THEME_STORAGE_KEY). `?theme=light|dark|system` in the address wins, for that visit, and is not kept;
10
10
  * - the theme in force is `<html data-theme="light|dark">`: explorer.css swaps its tokens on it,
11
11
  * theme-boot.js sets it before the first paint (so a light page never flashes dark), and this module
@@ -19,7 +19,7 @@
19
19
  import { state, touchScene } from './state.js';
20
20
  import { render } from './render.js';
21
21
  import { refreshMapStyle } from './map-style.js';
22
- import { THEME_STORAGE_KEY, nextChoice, resolveTheme, themeChoiceFrom, themeWords } from './theme-model.js';
22
+ import { THEME_STORAGE_KEY, resolveTheme, themeChoiceFrom } from './theme-model.js';
23
23
 
24
24
  const QUERY = '(prefers-color-scheme: light)';
25
25
  let choice = 'system';
@@ -49,14 +49,9 @@ function store(value) {
49
49
  } catch { /* storage blocked: the choice still holds for this visit */ }
50
50
  }
51
51
 
52
- function syncButton(theme) {
53
- const btn = document.getElementById('theme-toggle-btn');
54
- if (!btn) return;
55
- const words = themeWords(choice, theme);
56
- btn.setAttribute('aria-label', `${words}. Change theme`);
57
- btn.title = `${words}. Click for ${nextChoice(choice) === 'system' ? 'the system setting' : nextChoice(choice)}`;
58
- btn.dataset.choice = choice;
59
- btn.querySelectorAll('[data-icon]').forEach((g) => { g.toggleAttribute('hidden', g.dataset.icon !== choice); });
52
+ /** The segment in the account menu says which choice is on (aria-pressed) */
53
+ function syncButtons() {
54
+ for (const b of document.querySelectorAll('[data-action="set-theme"]')) b.setAttribute('aria-pressed', String(b.dataset.choice === choice));
60
55
  }
61
56
 
62
57
  /** Puts the theme in force on the page and the map */
@@ -64,7 +59,7 @@ function apply() {
64
59
  const theme = resolveTheme(choice, prefersLight());
65
60
  const root = document.documentElement;
66
61
  root.dataset.theme = theme;
67
- syncButton(theme);
62
+ syncButtons();
68
63
  refreshMapStyle(); // the map's tokens (--corn-map-*) differ by theme: read them for this one (map-style.js)
69
64
  if (state.theme === theme) return;
70
65
  state.theme = theme;
@@ -101,6 +96,3 @@ export function setThemeChoice(next) {
101
96
  store(choice);
102
97
  apply();
103
98
  }
104
-
105
- /** The header toggle: system, light, dark, system ... */
106
- export const cycleTheme = () => setThemeChoice(nextChoice(choice));
package/explorer/view.js CHANGED
@@ -157,13 +157,13 @@ export function setView(view) {
157
157
 
158
158
  export function syncViewUi() {
159
159
  const preset = state.view === 'dataflow';
160
+ // The View switch: the Map button is on for the map itself; Flow and House say theirs (house.js) in aria-pressed too
161
+ const map = $('preset-map-btn');
162
+ if (map) map.setAttribute('aria-pressed', String(state.view !== 'dataflow' && state.view !== 'house'));
160
163
  const btn = $('preset-dataflow-btn');
161
- if (btn) {
162
- btn.classList.toggle('hx-btn--active', preset);
163
- btn.setAttribute('aria-pressed', String(preset));
164
- }
164
+ if (btn) btn.setAttribute('aria-pressed', String(preset));
165
165
  const layersBtn = $('legend-toggle-btn');
166
- if (layersBtn) layersBtn.classList.toggle('hx-btn--dim', preset);
166
+ if (layersBtn) layersBtn.classList.toggle('hx-layers-chip--dim', preset);
167
167
  const note = $('layers-preset-note');
168
168
  if (note) note.hidden = !preset;
169
169
  const badge = $('instruction-badge-text');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcorn245/cornfield",
3
- "version": "0.30.0",
3
+ "version": "0.32.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
@@ -259,6 +259,8 @@ export function clientConfig(config, signIn = false) {
259
259
  return {
260
260
  name: 'cornfield',
261
261
  version: PKG.version,
262
+ // Where cornfield's own docs are: the account menu's Docs link
263
+ docs: PKG.homepage,
262
264
  title: config.title,
263
265
  links: config.links || [],
264
266
  // The theme's names and default, never a file's path (docs/config.md#theme)