cornfield 0.33.0 → 0.34.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 CHANGED
@@ -190,6 +190,20 @@ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
190
190
  const isText = (v) => typeof v === 'string' && v.trim() !== '';
191
191
  /** A path inside the repo: relative, forward slashes, no `..` segment */
192
192
  const inRepo = (p) => isText(p) && !path.isAbsolute(p) && !p.split(/[\\/]/).includes('..');
193
+ /** A forge's origin: http(s), a host name or a bracketed IPv6 address, and a port; no user name, path, query, fragment or backslash */
194
+ const FORGE_ORIGIN = /^https?:\/\/([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*|\[[0-9A-Fa-f:.]+\])(?::\d{1,5})?\/?$/;
195
+ /**
196
+ * Whether `url` is a forge's origin, and one the URL parser keeps as written: a host it would rewrite to another
197
+ * (`https://2130706433` and `https://0x7f.1` are 127.0.0.1), an IPv6 address it cannot read, or a port past 65535 is not one
198
+ */
199
+ const isForgeOrigin = (url) => {
200
+ const m = typeof url === 'string' ? FORGE_ORIGIN.exec(url) : null;
201
+ if (!m) return false;
202
+ try {
203
+ const u = new URL(url);
204
+ return m[1].startsWith('[') || u.hostname === m[1].toLowerCase();
205
+ } catch { return false; }
206
+ };
193
207
 
194
208
  /**
195
209
  * What is wrong with a config object (as the file exports it, before defaults).
@@ -238,8 +252,11 @@ export function configProblems(c) {
238
252
  if (!isObject(c.forge)) out.push('"forge" is { type, url, repo }.');
239
253
  else {
240
254
  if (!FORGE_TYPES.includes(c.forge.type)) out.push(`forge.type is one of ${FORGE_TYPES.join(', ')}.`);
241
- if (c.forge.url !== undefined && !/^https?:\/\/[^/\s]+\/?$/.test(String(c.forge.url))) out.push('forge.url is the forge\'s origin, like https://github.com.');
242
- if (!/^[\w.-]+\/[\w.-]+$/.test(String(c.forge.repo || ''))) out.push('forge.repo is "owner/name".');
255
+ if (c.forge.url !== undefined && !isForgeOrigin(c.forge.url)) out.push('forge.url is the forge\'s origin, like https://github.com.');
256
+ // GitHub and GitHub Enterprise only speak https; a token over http would travel in the clear
257
+ else if (c.forge.url !== undefined && c.forge.type === 'github' && !/^https:/i.test(String(c.forge.url)) && !/^http:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/?$/i.test(String(c.forge.url))) out.push('forge.url for GitHub is https (http only for localhost): the token would otherwise travel in the clear.');
258
+ const repoParts = String(c.forge.repo || '').split('/');
259
+ if (!/^[\w.-]+\/[\w.-]+$/.test(String(c.forge.repo || '')) || repoParts.some((p) => /^\.+$/.test(p))) out.push('forge.repo is "owner/name".');
243
260
  if (c.forge.mergeMethod !== undefined && !MERGE_METHODS.includes(c.forge.mergeMethod)) out.push(`forge.mergeMethod is one of ${MERGE_METHODS.join(', ')}.`);
244
261
  if (c.forge.baseBranch !== undefined && !(typeof c.forge.baseBranch === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/.test(c.forge.baseBranch) && !c.forge.baseBranch.includes('..'))) out.push('forge.baseBranch is the branch spec pull requests go into, like "main".');
245
262
  }
package/core/contrast.js CHANGED
@@ -348,7 +348,7 @@ const toText = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, var(--
348
348
  export const TEXT_TOKENS = Object.freeze(['--corn-text', '--corn-text-2', '--corn-text-3', '--corn-accent-text', '--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-added-text', '--corn-edit-text']);
349
349
  /** The tinted backgrounds, with the text that sits on each */
350
350
  export const SOFT_PAIRS = Object.freeze([
351
- ['--corn-ok', '--corn-ok-soft'], ['--corn-warn', '--corn-warn-soft'], ['--corn-bad', '--corn-bad-soft'], ['--corn-info', '--corn-info-soft'],
351
+ ['--corn-ok', '--corn-ok-soft'],
352
352
  ['--corn-accent-text', '--corn-accent-soft'], ['--corn-hue-orange-text', '--corn-hue-orange-soft'],
353
353
  ]);
354
354
  /** Solid fills that carry `--corn-ground` as their text (a pressed data-flow button, a chip, the What-if toggle, the House chip) */
@@ -8,14 +8,15 @@
8
8
  * (`legend`), in the panel (`title`, `color`). The one place these live: scene.js, the legend, the panel and
9
9
  * the House view's Cloud band (CLOUD-08) all read them here; the outage colours (CLOUD-07) are `color`.
10
10
  * - `externalLayer(node)`: the Layers key of an `external` node, `cloud` or `web` (the public web, spec D3).
11
- * - `cloudBadges`, `planLabel`, `cloudUsedBy`: what the node panel shows of a cloud node, as data.
12
- * - `cloudPanelHtml(node, nodes, edges)`: that panel section as HTML (panels.js puts it in the drawer).
11
+ * - `planLabel`, `cloudUsedBy`: what the node panel shows of a cloud node, as data.
12
+ * - `cloudPanelHtml(node, nodes, edges)`: the node panel's facts for it, as HTML (panels.js puts them under the head).
13
13
  *
14
14
  * Nothing here reads an env var name, a token or a registry `match` list: a cloud node does not carry them, and
15
15
  * the panel shows only the node's own fields and the labels of the edges into it (the registry's words).
16
16
  */
17
17
 
18
18
  import { escapeHtml as esc } from '../core/text.js';
19
+ import { capped } from './capped.js';
19
20
 
20
21
  /**
21
22
  * When an outage bites, in order of how soon. `dash` is the scene edge's dash (world units, like a proposal
@@ -44,12 +45,6 @@ export function planLabel(plan) {
44
45
  return plan.note ? `${TIER_WORDS[plan.tier]} · ${plan.note}` : TIER_WORDS[plan.tier];
45
46
  }
46
47
 
47
- /** The kind and the roles, as the panel's badges: ['Cloud', 'runtime', 'account'], or ['Public web', 'not cloud'] */
48
- export function cloudBadges(node) {
49
- if (node.kind === 'web') return ['Public web', 'not cloud'];
50
- return ['Cloud', ...(node.roles || [])];
51
- }
52
-
53
48
  /** What a user of a cloud service is called, one and many (`nounOf(type, n)`: the outage scenario's words too) */
54
49
  const NOUNS = {
55
50
  container: ['container', 'containers'], machine: ['machine', 'machines'], app: ['app', 'apps'],
@@ -92,60 +87,48 @@ export function cloudUsedBy(node, nodes, edges) {
92
87
  return out;
93
88
  }
94
89
 
95
- /** More users of one kind than this, in one group, fold into a count ("42 containers") with the list behind it */
96
- export const FOLD_AT = 8;
90
+ /** The fact names for the groups of users, short enough for the panel's key column (the long words are WHEN_STYLES `title`) */
91
+ const WHEN_KEYS = { run: 'Breaks now', deploy: 'Breaks on deploy', renew: 'Breaks on renewal' };
97
92
 
98
- const sec = (title, body) => `<div class="hx-sec" data-corn="section"><strong class="hx-strong">${title}</strong>${body}</div>`;
99
- const row = (color, arrow, body) => `<div class="hx-line"><span class="hx-glyph" style="--glyph:${color}">${arrow}</span><span>${body}</span></div>`;
93
+ const fact = (key, rows) => (rows.length ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">${esc(key)}</div><div class="hx-fact-v">${capped(rows)}</div></div>` : '');
94
+ const line = (body) => `<div class="hx-line">${body}</div>`;
100
95
  const name = (label) => `<span class="hx-name">${esc(label)}</span>`;
101
96
 
102
- function userRow(item, color) {
97
+ /** One user of the node: its name, (browser) when the visitor's browser makes the call, the edge's labels, and what it is when the group mixes kinds */
98
+ function userRow(item, mixed) {
103
99
  const browser = item.browser ? ' <span class="hx-cloud-browser">(browser)</span>' : '';
104
- return row(color, '←', `${name(item.label)}${browser}${item.via ? `<span class="hx-faint"> · ${esc(item.via)}</span>` : ''}`);
100
+ const bits = [mixed ? nounOf(item.type, 1) : '', item.via].filter(Boolean);
101
+ return line(`<span>${name(item.label)}${browser}${bits.length ? `<span class="hx-faint"> · ${esc(bits.join(' · '))}</span>` : ''}</span>`);
105
102
  }
106
103
 
107
- function groupHtml(group) {
108
- const lists = group.types.map((t) => {
109
- const rows = t.items.map((i) => userRow(i, group.color)).join('');
110
- if (t.items.length <= FOLD_AT) return rows;
111
- return `<details class="hx-cloud-fold"><summary>${t.items.length} ${esc(nounOf(t.type, t.items.length))}</summary>${rows}</details>`;
112
- }).join('');
113
- return `<div class="hx-cloud-when hx-cloud-when--${group.when}">`
114
- + `<div class="hx-cloud-when-head"><span class="hx-swatch-line hx-swatch-when hx-swatch-when--${group.when}"></span>`
115
- + `<span class="hx-glyph" style="--glyph:${group.color}">${esc(group.title)}</span><span class="hx-count">${group.count}</span></div>${lists}</div>`;
116
- }
117
-
118
- /** The Play button (spec 0031 section 8, CLOUD-07): main.js plays outage-model.js `outageScenario` for the node */
119
- const playButton = (node) => `<div class="hx-sec" data-corn="section"><button type="button" class="hx-btn hx-cloud-play" data-action="play-outage" data-id="${esc(node.id)}">▶ Play: ${esc(String(node.label || node.id))} is down</button></div>`;
104
+ /** The Play button (spec 0031 section 8, CLOUD-07): main.js plays outage-model.js `outageScenario` for the node. A quiet button under the facts. */
105
+ const playButton = (node) => `<button type="button" class="hx-btn hx-btn--quiet hx-cloud-play" data-action="play-outage" data-id="${esc(node.id)}">Play: ${esc(String(node.label || node.id))} is down</button>`;
120
106
 
121
107
  /**
122
- * The node panel's section for a cloud node (kind `cloud`) or the public web (kind `web`): badges and plan,
123
- * "If it's down", Used by grouped by when, the Play button (a cloud node only), what it relies on itself (calls to other cloud nodes) and the
124
- * webhooks it sends. The caller adds the doc link.
108
+ * The node panel's facts for a cloud node (kind `cloud`) or the public web (kind `web`), in the node panel's key/value
109
+ * rows (the type and the name are the panel's head): Plan, Roles, If it's down, who uses it by when its outage bites
110
+ * (one fact per `when` that has any, long lists folded by capped.js), what it relies on itself (calls to other cloud
111
+ * nodes), the webhooks it sends, then a quiet Play button (a cloud node only). The caller adds the File line.
125
112
  */
126
113
  export function cloudPanelHtml(node, nodes, edges) {
127
114
  const byId = new Map(nodes.map((n) => [n.id, n]));
128
115
  const label = (id) => String((byId.get(id) || { label: id }).label || id);
129
- const [kind, ...roles] = cloudBadges(node);
130
- const tier = node.kind === 'web' ? null : (node.plan && TIER_WORDS[node.plan.tier] ? node.plan.tier : 'unknown');
131
- const badges = `<div class="hx-cloud-badges"><span class="hx-cloud-badge hx-cloud-badge--${node.kind === 'web' ? 'web' : 'kind'}" data-corn="badge">${esc(kind)}</span>`
132
- + roles.map((r) => `<span class="hx-cloud-badge" data-corn="badge">${esc(r)}</span>`).join('')
133
- + (tier ? `<span class="hx-cloud-plan hx-cloud-plan--${tier}">${esc(TIER_WORDS[tier])}</span>` : '')
134
- + '</div>'
135
- + (tier && node.plan && node.plan.note ? `<div class="hx-faint hx-cloud-plan-note">${esc(node.plan.note)}</div>` : '');
136
-
137
- const groups = cloudUsedBy(node, nodes, edges);
138
- const usedBy = groups.length ? groups.map(groupHtml).join('') : '<div class="hx-faint">Nothing on the map uses it.</div>';
116
+ const web = node.kind === 'web'; // the public web: no plan, no roles, no Play
117
+ const roles = web ? [] : node.roles || [];
118
+ const used = cloudUsedBy(node, nodes, edges).map((g) => {
119
+ const mixed = g.types.length > 1;
120
+ return fact(WHEN_KEYS[g.when], g.types.flatMap((t) => t.items.map((i) => userRow(i, mixed))));
121
+ }).join('') || fact('Used by', [line('<span class="hx-faint">Nothing on the map uses it.</span>')]);
139
122
 
140
123
  const relies = edges.filter((e) => e.kind === 'calls' && e.from === node.id && (byId.get(e.to) || {}).type === 'external')
141
- .map((e) => row(WHEN_STYLES[whenOf(e)].color, '→', `${name(label(e.to))}${e.label ? `<span class="hx-faint"> · ${esc(e.label)}</span>` : ''}`));
142
- const pushes = edges.filter((e) => e.kind === 'delivers' && e.from === node.id).map((e) => row('#94a3b8', '→', name(label(e.to))));
143
-
144
- return `<div class="hx-cloud">${badges}`
145
- + sec('If it\'s down:', `<div class="hx-cloud-breaks">${esc(node.breaks || 'Not described yet.')}</div>`)
146
- + sec('Used by:', usedBy)
147
- + (node.kind === 'web' ? '' : playButton(node)) // the public web is never down as a whole (spec D3)
148
- + (relies.length ? sec('Relies on:', relies.join('')) : '')
149
- + (pushes.length ? sec('Pushes to (webhook):', pushes.join('')) : '')
150
- + '</div>';
124
+ .map((e) => line(`<span>${name(label(e.to))}${e.label ? `<span class="hx-faint"> · ${esc(e.label)}</span>` : ''}</span>`));
125
+ const pushes = edges.filter((e) => e.kind === 'delivers' && e.from === node.id).map((e) => line(name(label(e.to))));
126
+
127
+ return (web ? '' : fact('Plan', [line(esc(planLabel(node.plan) || TIER_WORDS.unknown))]))
128
+ + fact('Roles', roles.length ? [line(esc(roles.join(', ')))] : [])
129
+ + fact('If it\'s down', [line(esc(node.breaks || 'Not described yet.'))])
130
+ + used
131
+ + fact('Relies on', relies)
132
+ + fact('Pushes to', pushes)
133
+ + (web ? '' : playButton(node)); // the public web is never down as a whole (spec D3)
151
134
  }
@@ -66,7 +66,7 @@ h1, h2, h3, p { margin: 0; }
66
66
  .hx-chips { display: flex; flex-wrap: wrap; gap: var(--corn-space-1); padding-top: var(--corn-space-1); }
67
67
  .hx-pt { padding-top: var(--corn-space-3); }
68
68
  /* Headings and titles take the display family (the same as the body unless a brand sets it) */
69
- .hx-title, .hx-drawer-title, .hx-block-title, .hx-menu-title, .hx-confirm-title, .hx-mockup-title { font-family: var(--corn-font-display); }
69
+ .hx-title, .hx-drawer-title, .hx-menu-title, .hx-confirm-title, .hx-mockup-title { font-family: var(--corn-font-display); }
70
70
 
71
71
  /* ==== the header (CF-41) ===============================================================================================
72
72
  Left to right: the brand, the View switch (Map, Flow, House, Fit), the Layers chip, the live chip; at the right the search,
@@ -350,7 +350,6 @@ h1, h2, h3, p { margin: 0; }
350
350
  .hx-lead { font-size: var(--corn-text-base); line-height: 1.5; color: var(--corn-text-2); }
351
351
 
352
352
  .hx-block { display: flex; flex-direction: column; gap: var(--corn-space-3); }
353
- .hx-block-title { font-size: var(--corn-text-sm); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--corn-text-2); }
354
353
  .hx-meta { display: flex; flex-direction: column; gap: var(--corn-space-5); font-size: var(--corn-text-md); color: var(--corn-text-2); overflow-wrap: anywhere; }
355
354
  .hx-meta > :empty { display: none; } /* no live data, no threads: no gap where they would be */
356
355
 
@@ -506,8 +505,7 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
506
505
  .hx-whatif-target { font-size: var(--corn-text-xs); }
507
506
  .hx-whatif-addstep { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2); margin-top: var(--corn-space-3); }
508
507
  .hx-whatif-addstep .hx-whatif-field { flex: 1 1 220px; }
509
- .hx-whatif-drawer .hx-btn { margin-top: var(--corn-space-1); }
510
- .hx-whatif-edges { margin-top: var(--corn-space-3); color: var(--corn-text-2); }
508
+ .hx-whatif-edges { color: var(--corn-text-2); }
511
509
  .hx-whatif-edges summary { cursor: pointer; }
512
510
  .hx-whatif-edges .hx-whatif-list { margin-top: var(--corn-space-2); max-height: 200px; overflow: auto; }
513
511
  #graph-canvas.is-drawing-edge { touch-action: none; }
@@ -701,24 +699,7 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
701
699
  .hx-swatch-when--deploy { color: var(--corn-changed); background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px); }
702
700
  .hx-swatch-when--renew { color: var(--corn-edit); background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); }
703
701
  .hx-swatch-when--plain { color: var(--corn-text-2); } /* the legend: the map draws every call in the calls colour, so only the pattern is the key */
704
- .hx-cloud-badges { display: flex; flex-wrap: wrap; gap: var(--corn-space-1); padding-top: var(--corn-space-2); }
705
- .hx-cloud-badge, .hx-cloud-plan { padding: calc(var(--corn-space-1) / 2) var(--corn-space-2); border-radius: var(--corn-radius-pill); border: var(--corn-border) solid color-mix(in srgb, var(--corn-text-3) 35%, transparent); background: color-mix(in srgb, var(--corn-text-3) 12%, transparent); color: var(--corn-text-2); font-family: var(--corn-font); font-size: var(--corn-text-2xs); font-weight: 600; }
706
- .hx-cloud-badge--kind { border-color: color-mix(in srgb, var(--corn-info) 45%, transparent); background: var(--corn-info-soft); color: var(--corn-info); }
707
- .hx-cloud-badge--web { border-color: color-mix(in srgb, var(--corn-text-2) 45%, transparent); background: color-mix(in srgb, var(--corn-text-2) 12%, transparent); color: var(--corn-text-2); }
708
- .hx-cloud-plan { margin-left: auto; }
709
- .hx-cloud-plan--free { border-color: color-mix(in srgb, var(--corn-ok) 45%, transparent); background: var(--corn-ok-soft); color: var(--corn-ok); }
710
- .hx-cloud-plan--paid { border-color: color-mix(in srgb, var(--corn-warn) 50%, transparent); background: var(--corn-warn-soft); color: var(--corn-warn); }
711
- .hx-cloud-plan--unknown { border-style: dashed; color: var(--corn-text-3); }
712
- .hx-cloud-plan--off { border-color: color-mix(in srgb, var(--corn-bad) 45%, transparent); background: var(--corn-bad-soft); color: var(--corn-bad); }
713
- .hx-cloud-plan-note { padding-top: calc(var(--corn-space-1) / 2); text-align: right; font-size: var(--corn-text-2xs); }
714
- .hx-cloud-breaks { padding: var(--corn-space-1) 0 calc(var(--corn-space-1) / 2); color: var(--corn-text-2); font-family: var(--corn-font); line-height: 1.5; }
715
- .hx-cloud-when { padding-top: var(--corn-space-1); }
716
- .hx-cloud-when-head { display: flex; align-items: center; gap: var(--corn-space-2); padding: calc(var(--corn-space-1) / 2) 0; font-weight: 600; }
717
- .hx-cloud-when-head .hx-swatch-when { flex: none; }
718
- .hx-cloud-fold > summary { cursor: pointer; padding: calc(var(--corn-space-1) / 2) 0 calc(var(--corn-space-1) / 2) var(--corn-space-5); color: var(--corn-text-2); }
719
- .hx-cloud-fold[open] > summary { color: var(--corn-text-2); }
720
- .hx-cloud-browser { color: var(--corn-info); font-size: var(--corn-text-2xs); }
721
- .hx-cloud-play { width: 100%; justify-content: center; } /* the cloud panel's "Play: X is down" (spec 0031 section 8) */
702
+ .hx-cloud-browser { color: var(--corn-text-3); font-size: var(--corn-text-sm); }
722
703
 
723
704
  /* ---- a panel glyph (MAP-01) ----------------------------------------------------------------------
724
705
  A panel glyph's colour comes from script (the flow or kind it stands for, --glyph): mixed with the text colour by
@@ -1008,11 +989,16 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
1008
989
  /* a phone: the sheet's actions are full width at the foot, each a 44px target */
1009
990
  .hx-drawer-foot { flex-direction: column; }
1010
991
  .hx-drawer-foot .hx-open, .hx-foot-btn { min-height: 44px; }
1011
- .hx-drawer .hx-row, .hx-drawer .hx-mockup-open, .hx-textact { min-height: 44px; }
992
+ .hx-drawer .hx-row, .hx-drawer .hx-mockup-open, .hx-textact, .hx-drawer .hx-whatif-drawer .hx-btn, .hx-drawer .hx-whatif-drawer select, .hx-drawer .hx-whatif-edges summary, .hx-cloud-play { min-height: 44px; }
1012
993
  .hx-drawer .hx-close { width: 44px; height: 44px; }
1013
994
  }
1014
- .hx-drawer .hx-whatif-drawer { font-size: var(--corn-text-md); color: var(--corn-text-2); }
995
+ .hx-drawer .hx-whatif-drawer { align-items: flex-start; gap: var(--corn-space-2); font-size: var(--corn-text-md); color: var(--corn-text-2); }
996
+ .hx-whatif-drawer:focus { outline: none; } /* it only holds the focus between two paints */
997
+ .hx-drawer .hx-whatif-edgeto { display: flex; align-items: center; gap: var(--corn-space-2); align-self: stretch; }
998
+ .hx-drawer .hx-whatif-edgeto .hx-whatif-field { flex: 1; min-width: 0; }
1015
999
  .hx-drawer .hx-whatif-drawer select { max-width: 100%; }
1000
+ .hx-drawer .hx-whatif-edges { align-self: stretch; }
1001
+ .hx-cloud-play { align-self: flex-start; } /* the cloud panel's "Play: X is down", a quiet button under the facts (spec 0031 section 8) */
1016
1002
  .hx-drawer-foot .hx-btn--quiet { border-color: transparent; background: none; text-decoration: none; }
1017
1003
  .hx-more { display: contents; }
1018
1004
  .hx-more[hidden] { display: none; }
@@ -50,9 +50,6 @@
50
50
  --corn-bad: #fca5a5;
51
51
  --corn-info: #7dd3fc;
52
52
  --corn-ok-soft: color-mix(in srgb, var(--corn-ok) 15%, transparent);
53
- --corn-warn-soft: color-mix(in srgb, var(--corn-warn) 14%, transparent);
54
- --corn-bad-soft: color-mix(in srgb, var(--corn-bad) 12%, transparent);
55
- --corn-info-soft: color-mix(in srgb, var(--corn-info) 15%, transparent);
56
53
 
57
54
  /* Diff: what a proposal adds, changes, removes and edits (the map draws the same four) */
58
55
  --corn-added: #2dd4bf;
@@ -535,6 +535,7 @@ function mountDrawerBox() {
535
535
  drawerBox.id = 'whatif-drawer';
536
536
  drawerBox.className = 'hx-block hx-whatif-drawer';
537
537
  drawerBox.hidden = true;
538
+ drawerBox.tabIndex = -1; // holds the focus while it is painted again (paintDrawer)
538
539
  block.after(drawerBox); // under the facts, the mockups and the threads: the node comes first, the tools to edit it after
539
540
  drawerBox.addEventListener('click', onClick);
540
541
  return drawerBox;
@@ -560,30 +561,43 @@ function edgeToHtml(n) {
560
561
  .sort((a, b) => String(a.label).localeCompare(String(b.label)))
561
562
  .slice(0, EDGE_TO_MAX);
562
563
  if (!others.length) return '';
563
- return `<div class="hx-whatif-addstep hx-whatif-edgeto">
564
+ return `<div class="hx-whatif-edgeto">
564
565
  <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>
565
- <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>
566
+ <button type="button" class="hx-btn hx-btn--quiet" 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>
566
567
  </div>`;
567
568
  }
568
569
 
570
+ /** Paints the box; when the keyboard was in it (a Remove, a Bring back), the focus stays in it rather than falling to the page */
569
571
  function paintDrawer() {
570
572
  const box = mountDrawerBox();
571
573
  if (!box) return;
572
- const open = !!state.proposal && (!!state.selectedNode || !!state.selectedEdge);
574
+ const was = box.contains(document.activeElement) ? document.activeElement : null;
575
+ const same = (el) => el.tagName === was.tagName && ['whatif', 'id', 'from', 'to', 'kind', 'flow', 'edgeTo'].every((k) => el.dataset[k] === was.dataset[k]);
576
+ fillDrawer(box);
577
+ if (!was || box.hidden) return;
578
+ const next = [...box.querySelectorAll('button:not([disabled]), select, summary')].find(same)
579
+ // the button pressed is gone: Remove became Bring it back (or back again), or an edge left the list
580
+ || ((was.tagName === 'BUTTON' || was === box) && (box.querySelector('[data-whatif="bring-back"]:not([disabled])') || (was.closest('details') && box.querySelector('summary')) || box.querySelector('button:not([disabled])')))
581
+ || box; // nothing to hold it yet (the map is mid-rebuild): the box keeps it for the next paint
582
+ next.focus({ preventScroll: true });
583
+ }
584
+
585
+ function fillDrawer(box) {
586
+ const open = !!state.proposal && ui.editing && (!!state.selectedNode || !!state.selectedEdge); // behind the toolbar's Edit, like the rest of the what-if tools
573
587
  box.hidden = !open;
574
588
  if (!open) { box.innerHTML = ''; return; }
575
589
 
576
590
  const message = '<p class="hx-whatif-msg" data-msg="drawer" role="alert" hidden data-corn="message"></p>';
577
- const title = '<h3 class="hx-block-title">Try a change</h3>';
591
+ const title = '<h3 class="hx-sec-title">Try a change</h3>';
578
592
  if (state.selectedEdge) {
579
593
  const e = state.selectedEdge;
580
594
  const key = edgeKey(e);
581
595
  if (kindOfMark(e) === 'removed' && e.mark !== 'edit') { box.hidden = true; return; } // the proposal's own removal: not for an edit to undo
582
596
  if (e.mark === 'edit' && e.editOp === 'removed') {
583
597
  const i = removalIndex('remove-edge', (x) => edgeKey(x) === key);
584
- box.innerHTML = `${title}<p class="hx-faint">You removed this edge.</p><button type="button" class="hx-btn" data-whatif="bring-back" data-index="${i}"${i < 0 ? ' disabled' : ''}>Bring it back</button>${message}`;
598
+ box.innerHTML = `${title}<p class="hx-faint">You removed this edge.</p><button type="button" class="hx-btn hx-btn--quiet" data-whatif="bring-back" data-index="${i}"${i < 0 ? ' disabled' : ''}>Bring it back</button>${message}`;
585
599
  } else {
586
- box.innerHTML = `${title}<button type="button" class="hx-btn" data-whatif="remove-edge" data-from="${escHtml(e.from)}" data-to="${escHtml(e.to)}" data-kind="${escHtml(e.kind || '')}" data-flow="${escHtml(e.flow || '')}" title="Take this edge out of the proposal's map">Remove in this proposal</button>${message}`;
600
+ box.innerHTML = `${title}<button type="button" class="hx-btn hx-btn--quiet" data-whatif="remove-edge" data-from="${escHtml(e.from)}" data-to="${escHtml(e.to)}" data-kind="${escHtml(e.kind || '')}" data-flow="${escHtml(e.flow || '')}" title="Take this edge out of the proposal's map">Remove in this proposal</button>${message}`;
587
601
  }
588
602
  paintMessages();
589
603
  return;
@@ -593,7 +607,7 @@ function paintDrawer() {
593
607
  if (n.mark === 'removed') { box.hidden = true; return; } // the proposal's own removal
594
608
  if (n.mark === 'edit' && n.editOp === 'removed') {
595
609
  const i = removalIndex('remove-node', (x) => x.id === n.id);
596
- box.innerHTML = `${title}<p class="hx-faint">You removed this node.</p><button type="button" class="hx-btn" data-whatif="bring-back" data-index="${i}"${i < 0 ? ' disabled' : ''}>Bring it back</button>${message}`;
610
+ box.innerHTML = `${title}<p class="hx-faint">You removed this node.</p><button type="button" class="hx-btn hx-btn--quiet" data-whatif="bring-back" data-index="${i}"${i < 0 ? ' disabled' : ''}>Bring it back</button>${message}`;
597
611
  paintMessages();
598
612
  return;
599
613
  }
@@ -602,7 +616,7 @@ function paintDrawer() {
602
616
  const rows = shown.map((e) => `<li class="hx-whatif-edit"><span class="hx-whatif-edit-text">${escHtml(edgeName(e))} <span class="hx-faint">${escHtml(e.kind === 'flow' ? `flow, ${e.flow}` : e.kind || 'ownership')}</span></span><button type="button" class="hx-textbtn" data-whatif="remove-edge" data-from="${escHtml(e.from)}" data-to="${escHtml(e.to)}" data-kind="${escHtml(e.kind || '')}" data-flow="${escHtml(e.flow || '')}" aria-label="Remove the edge ${escHtml(edgeName(e))}">Remove</button></li>`);
603
617
  const help = n.mark === 'edit' || n.mark === 'added' ? 'Takes it out of this proposal, with whatever hangs on it.' : 'Shows the map without it.';
604
618
  box.innerHTML = `${title}
605
- <button type="button" class="hx-btn" data-whatif="remove-node" data-id="${escHtml(n.id)}" title="${escHtml(help)}">Remove in this proposal</button>
619
+ <button type="button" class="hx-btn hx-btn--quiet" data-whatif="remove-node" data-id="${escHtml(n.id)}" title="${escHtml(help)}">Remove in this proposal</button>
606
620
  ${edgeToHtml(n)}
607
621
  ${edges.length ? `<details class="hx-whatif-edges"><summary>Its edges (${edges.length})</summary><ul class="hx-whatif-list">${rows.join('')}</ul>${edges.length > shown.length ? `<p class="hx-faint">and ${edges.length - shown.length} more</p>` : ''}</details>` : ''}
608
622
  ${message}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.33.0",
3
+ "version": "0.34.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/forge.js CHANGED
@@ -141,7 +141,8 @@ const MAX_LABELS = 5;
141
141
  const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
142
142
  const MERGE_METHODS = ['merge', 'squash', 'rebase'];
143
143
  const STATES = ['open', 'closed', 'all'];
144
- const REPO = /^[\w.-]+\/[\w.-]+$/;
144
+ /** owner/name, neither made only of dots (`..` would walk out of `repos/` in the API's path) */
145
+ const REPO = /^(?!\.+\/)[\w.-]+\/(?!\.+$)[\w.-]+$/;
145
146
  /** A tag name a release draft may carry: no spaces, no `..`, no leading dash, at most 100 characters */
146
147
  const TAG_NAME = /^[\w][\w./+-]{0,99}$/;
147
148
  /** The most a release's body may hold (GitHub's own limit) */