@popcorn245/cornfield 0.29.0 → 0.31.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/mentions.js +1 -1
- package/core/strings.js +4 -5
- package/explorer/account-menu.js +89 -0
- package/explorer/capped.js +33 -0
- package/explorer/explorer.css +195 -106
- package/explorer/flows.js +5 -7
- package/explorer/forge-panel.js +8 -5
- package/explorer/house.css +3 -7
- package/explorer/house.js +1 -1
- package/explorer/index.html +76 -91
- package/explorer/keyboard.js +21 -1
- package/explorer/layers.js +9 -0
- package/explorer/main.js +12 -9
- package/explorer/mockups-model.js +1 -1
- package/explorer/panels.js +146 -87
- package/explorer/plugins.js +45 -15
- package/explorer/proposal.js +15 -10
- package/explorer/render.js +0 -5
- package/explorer/review-tokens.js +2 -1
- package/explorer/state.js +1 -1
- package/explorer/theme-model.js +0 -9
- package/explorer/theme.js +6 -14
- package/explorer/tokens.css +1 -0
- package/explorer/view.js +5 -5
- package/explorer/whatif.js +1 -1
- package/package.json +1 -1
- package/server/server.js +2 -0
package/explorer/panels.js
CHANGED
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
|
|
9
9
|
import { state, nodeById, nameOf, escHtml, touchScene } from './state.js';
|
|
10
10
|
import { render } from './render.js';
|
|
11
|
-
import {
|
|
11
|
+
import { flowSummary } from './flows.js';
|
|
12
12
|
import { clearScenario } from './scenario-ui.js';
|
|
13
|
-
import {
|
|
13
|
+
import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
|
|
14
14
|
import { nodeMockupsHtml } from './mockups-model.js';
|
|
15
15
|
import { collapseSheet } from './sheets.js';
|
|
16
16
|
import { liveSection, hydrateLivePhotos } from './live.js';
|
|
17
17
|
import { cloudPanelHtml } from './cloud-model.js';
|
|
18
18
|
import { t } from './strings.js';
|
|
19
|
+
import { capped, toggleCapped } from './capped.js';
|
|
20
|
+
import { canStartAgent, openProposalStart } from './forge-panel.js';
|
|
19
21
|
|
|
20
22
|
const $ = (id) => document.getElementById(id);
|
|
21
23
|
|
|
@@ -24,9 +26,23 @@ const $ = (id) => document.getElementById(id);
|
|
|
24
26
|
// ---------------------------------------------------------------------------
|
|
25
27
|
const code = (s) => `<code class="hx-code">${escHtml(s)}</code>`;
|
|
26
28
|
const nm = (id) => `<span class="hx-name">${escHtml(nameOf(id))}</span>`;
|
|
27
|
-
const line = (
|
|
28
|
-
|
|
29
|
-
const
|
|
29
|
+
const line = (body) => `<div class="hx-line">${body}</div>`;
|
|
30
|
+
/** The words a fact goes by in the panel: short nouns, whatever the longer sentence it was built from */
|
|
31
|
+
const FACT_KEYS = {
|
|
32
|
+
'Uses design tokens': 'Tokens', 'Loaded by the server per request': 'Loaded by', 'Domains served (Caddyfile → service)': 'Domains', 'Compose file': 'File',
|
|
33
|
+
'Baked pages': 'Baked', 'Reads tables': 'Reads', 'Writes tables': 'Writes', 'Self-hosted': 'Role', 'Pushes to (webhook)': 'Pushes to',
|
|
34
|
+
'Calls outside': 'Calls', 'Client modules': 'Modules', 'Data flows': 'Flows',
|
|
35
|
+
};
|
|
36
|
+
const FACT_COUNTED = /^(?:Defines )?\d+ (?:CSS )?(variable|service)\(s\)$/;
|
|
37
|
+
const factKey = (title) => {
|
|
38
|
+
const plain = title.replace(/:$/, '');
|
|
39
|
+
const counted = FACT_COUNTED.exec(plain);
|
|
40
|
+
if (counted) return counted[1] === 'service' ? 'Services' : plain.startsWith('Defines') ? 'Defines' : 'Variables';
|
|
41
|
+
return FACT_KEYS[plain] || plain;
|
|
42
|
+
};
|
|
43
|
+
/** One fact: its name, and what it says. A fact with nothing in it is not shown. */
|
|
44
|
+
const section = (title, rows) => (rows.length ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">${escHtml(factKey(title))}</div><div class="hx-fact-v">${capped(rows)}</div></div>` : '');
|
|
45
|
+
const varList = (vars) => `<div class="hx-chips">${capped(vars.map((v) => `<code class="hx-var">${escHtml(v)}</code>`))}</div>`;
|
|
30
46
|
const edgesOf = (kind, side, id) => state.edges.filter((e) => e.kind === kind && e[side] === id);
|
|
31
47
|
|
|
32
48
|
/** Table <-> page data: which keys a page's render reads, which forms write, what ROM re-bakes */
|
|
@@ -35,93 +51,93 @@ function dataSummary(node) {
|
|
|
35
51
|
const writes = state.edges.filter((e) => e.kind === 'writes');
|
|
36
52
|
const usesOut = state.edges.filter((e) => e.kind === 'uses' && e.from === node.id);
|
|
37
53
|
const extendsOut = state.edges.filter((e) => e.kind === 'extends' && e.from === node.id);
|
|
38
|
-
const common = section('Extends:', extendsOut.map((e) => line(
|
|
39
|
-
+ section('Uses design tokens:', usesOut.map((e) => line(
|
|
54
|
+
const common = section('Extends:', extendsOut.map((e) => line(nm(e.to))))
|
|
55
|
+
+ section('Uses design tokens:', usesOut.map((e) => line(`${nm(e.to)} · ${e.vars.length}${varList(e.vars)}`)))
|
|
40
56
|
+ (node.type !== 'token' && node.vars ? section(`Defines ${node.vars.length} CSS variable(s):`, [varList(node.vars)]) : '');
|
|
41
57
|
|
|
42
58
|
if (node.type === 'app') {
|
|
43
59
|
const served = node.deployed
|
|
44
|
-
? line(
|
|
45
|
-
: line('
|
|
60
|
+
? line(`${/^https?:\/\//.test(node.url) ? `<a class="hx-link" href="${escHtml(node.url)}" target="_blank" rel="noreferrer">${escHtml(node.url)}</a>` : code(node.url)} → ${(node.upstreams || []).map(code).join(' ')}${node.stack ? ` <span class="hx-faint">[${escHtml(node.stack)}]</span>` : ''}`)
|
|
61
|
+
: line('Not deployed by any stack in this repo');
|
|
46
62
|
const runsOn = state.edges.filter((e) => e.kind === 'runs-on' && e.from === node.id)
|
|
47
|
-
.map((e) => line(
|
|
63
|
+
.map((e) => line(`${nm(e.to)}${(e.mappings || []).map((m) => `<div class="hx-faint">${code(m.host)} → ${code(m.upstream)}${m.service ? ` = ${code(m.service)}` : ''}</div>`).join('')}`));
|
|
48
64
|
return section('Served:', [served])
|
|
49
65
|
+ section('Runs on:', runsOn)
|
|
50
|
-
+ section('Loaded by the server per request:', reads.filter((e) => e.to === node.id).map((e) => line(
|
|
66
|
+
+ section('Loaded by the server per request:', reads.filter((e) => e.to === node.id).map((e) => line(nm(e.from))))
|
|
51
67
|
+ common;
|
|
52
68
|
}
|
|
53
69
|
if (node.type === 'token') {
|
|
54
70
|
const users = state.edges.filter((e) => e.kind === 'uses' && e.to === node.id);
|
|
55
71
|
return section(`${node.vars.length} variable(s):`, [varList(node.vars)])
|
|
56
|
-
+ section('Used by:', users.map((e) => line(
|
|
72
|
+
+ section('Used by:', users.map((e) => line(`${nm(e.from)} · ${escHtml(e.vars.join(' '))}`)));
|
|
57
73
|
}
|
|
58
74
|
if (['atom', 'molecule', 'core'].includes(node.type)) {
|
|
59
|
-
const pages = state.edges.filter((e) => e.dashed && e.to === node.id).map((e) => line(
|
|
60
|
-
return (node.table ? section('Record of:', [line(
|
|
75
|
+
const pages = state.edges.filter((e) => e.dashed && e.to === node.id).map((e) => line(nm(e.from)));
|
|
76
|
+
return (node.table ? section('Record of:', [line(`${escHtml(node.model)} · table ${code(node.table)}`)]) : '')
|
|
61
77
|
+ section('Rendered by:', pages) + common;
|
|
62
78
|
}
|
|
63
79
|
if (node.type === 'stack') {
|
|
64
80
|
const served = state.edges.filter((e) => e.kind === 'runs-on' && e.to === node.id);
|
|
65
|
-
return section('Domains served (Caddyfile → service):', served.flatMap((e) => (e.mappings || []).map((m) => line(
|
|
66
|
-
+ section(`${(node.services || []).length} service(s):`, (node.services || []).map((s) => line(
|
|
67
|
-
+ section('Compose file:', [line(
|
|
81
|
+
return section('Domains served (Caddyfile → service):', served.flatMap((e) => (e.mappings || []).map((m) => line(`<span class="hx-name">${escHtml(m.host)}</span> → ${code(m.upstream)}${m.service ? ` = ${code(m.service)}` : ''}`))))
|
|
82
|
+
+ section(`${(node.services || []).length} service(s):`, (node.services || []).map((s) => line(`<span class="hx-name">${escHtml(s.name)}</span>${s.image ? ` <span class="hx-faint">${escHtml(s.image)}</span>` : ''}${s.ports.length ? `<div>${s.ports.map(code).join(' ')}</div>` : ''}${s.volumes.length ? `<div class="hx-faint">${s.volumes.map(escHtml).join('<br>')}</div>` : ''}`)))
|
|
83
|
+
+ section('Compose file:', [line(code(node.file))]);
|
|
68
84
|
}
|
|
69
85
|
if (node.type === 'table') {
|
|
70
86
|
const readers = reads.filter((e) => e.from === node.id);
|
|
71
87
|
const writers = writes.filter((e) => e.to === node.id);
|
|
72
88
|
const baked = readers.filter((e) => (nodeById(e.to) || {}).render?.rom === 'bake');
|
|
73
|
-
return (node.model ? section('Model:', [line(
|
|
74
|
-
+ section('Read by:', readers.map((e) => line(
|
|
75
|
-
+ section('Written by:', writers.map((e) => line(
|
|
76
|
-
+ (baked.length ? section('Baked pages:', [line(
|
|
89
|
+
return (node.model ? section('Model:', [line(escHtml(node.model))]) : '')
|
|
90
|
+
+ section('Read by:', readers.map((e) => line(`${nm(e.to)} · ${e.keys.map(code).join(' ')}`)))
|
|
91
|
+
+ section('Written by:', writers.map((e) => line(`${nm(e.from)} · ${escHtml(e.label)}`)))
|
|
92
|
+
+ (baked.length ? section('Baked pages:', [line(`a write here re-bakes <span class="hx-rom hx-bold">${baked.length}</span> file(s): ${baked.map((e) => escHtml(nameOf(e.to))).join(', ')}`)]) : '');
|
|
77
93
|
}
|
|
78
94
|
if (node.type === 'service') {
|
|
79
95
|
const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'imports' ? ` · ${escHtml(e.label)}` : ''}`;
|
|
80
|
-
return section('Kind:', [line(
|
|
81
|
-
+ section('Started by:', [...(node.triggers || []).map((t) => line(
|
|
82
|
-
+ section('Jobs:', (node.jobs || []).map((j) => line(
|
|
83
|
-
+ section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(
|
|
84
|
-
+ section('Calls:', edgesOf('calls', 'from', node.id).map((e) => line(
|
|
85
|
-
+ section('Called by:', edgesOf('calls', 'to', node.id).map((e) => line(
|
|
86
|
-
+ section('Reads tables:', reads.filter((e) => e.to === node.id).map((e) => line(
|
|
87
|
-
+ section('Writes tables:', writes.filter((e) => e.from === node.id).map((e) => line(
|
|
88
|
-
+ section('Mechanisms:', (node.mechanisms || []).map((m) => line(
|
|
96
|
+
return section('Kind:', [line(`${code(node.kind)}${node.summary ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
|
|
97
|
+
+ section('Started by:', [...(node.triggers || []).map((t) => line(escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(row(e, 'from')))])
|
|
98
|
+
+ section('Jobs:', (node.jobs || []).map((j) => line(`${code(j.name)} · cron ${code(j.cron)}`)))
|
|
99
|
+
+ section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(row(e, 'to'))))
|
|
100
|
+
+ section('Calls:', edgesOf('calls', 'from', node.id).map((e) => line(row(e, 'to'))))
|
|
101
|
+
+ section('Called by:', edgesOf('calls', 'to', node.id).map((e) => line(row(e, 'from'))))
|
|
102
|
+
+ section('Reads tables:', reads.filter((e) => e.to === node.id).map((e) => line(nm(e.from))))
|
|
103
|
+
+ section('Writes tables:', writes.filter((e) => e.from === node.id).map((e) => line(nm(e.to))))
|
|
104
|
+
+ section('Mechanisms:', (node.mechanisms || []).map((m) => line(escHtml(m))));
|
|
89
105
|
}
|
|
90
106
|
if (node.type === 'container' && node.selfHosted) {
|
|
91
107
|
// A self-hosted service is the container that runs it (spec 0031 section 3): what the API uses it for, who calls it, its webhook
|
|
92
108
|
const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'calls' ? ` · ${escHtml(e.label)}` : ''}`;
|
|
93
109
|
const into = state.edges.filter((e) => e.to === node.id && (e.kind === 'calls' || (e.kind === 'flow' && e.flow === 'api')));
|
|
94
|
-
const calledBy = (type) => into.filter((e) => nodeById(e.from)?.type === type).map((e) => line(
|
|
110
|
+
const calledBy = (type) => into.filter((e) => nodeById(e.from)?.type === type).map((e) => line(row(e, 'from')));
|
|
95
111
|
const stackmates = new Set(state.nodes.filter((n) => n.type === 'container' && n.stack === node.stack).map((n) => n.id));
|
|
96
|
-
return section('Self-hosted:', [line(
|
|
112
|
+
return section('Self-hosted:', [line(escHtml(node.summary || ''))])
|
|
97
113
|
+ section('Called by services:', calledBy('service'))
|
|
98
114
|
+ section('Called by endpoints:', calledBy('page'))
|
|
99
115
|
+ section('Called by apps:', calledBy('app'))
|
|
100
|
-
+ section('Pushes to (webhook):', state.edges.filter((e) => e.kind === 'delivers' && stackmates.has(e.from) && nodeById(e.to)?.type === 'page').map((e) => line(
|
|
116
|
+
+ section('Pushes to (webhook):', state.edges.filter((e) => e.kind === 'delivers' && stackmates.has(e.from) && nodeById(e.to)?.type === 'page').map((e) => line(`${nm(e.to)}${e.from === node.id ? '' : ` <span class="hx-faint">from ${escHtml(nameOf(e.from))}</span>`}`)));
|
|
101
117
|
}
|
|
102
118
|
if (node.type === 'external' && node.kind) { // a cloud node or the public web (spec 0031 section 6)
|
|
103
119
|
return cloudPanelHtml(node, state.nodes, state.edges); // its File line is the registry
|
|
104
120
|
}
|
|
105
121
|
if (node.type === 'external') {
|
|
106
122
|
const calledBy = (type) => edgesOf('calls', 'to', node.id).filter((e) => nodeById(e.from)?.type === type);
|
|
107
|
-
return section('System:', [line(
|
|
108
|
-
+ section('Client modules:', (node.modules || []).map((m) => line(
|
|
109
|
-
+ section('Called by services:', calledBy('service').map((e) => line(
|
|
110
|
-
+ section('Called by endpoints:', calledBy('page').map((e) => line(
|
|
111
|
-
+ section('Pushes to (webhook):', edgesOf('delivers', 'from', node.id).map((e) => line(
|
|
123
|
+
return section('System:', [line(`${escHtml(node.summary || '')}${node.host ? `<div class="hx-faint">Runs here as ${code(node.host)}</div>` : '<div class="hx-faint">Not run by this stack</div>'}`)])
|
|
124
|
+
+ section('Client modules:', (node.modules || []).map((m) => line(code(m))))
|
|
125
|
+
+ section('Called by services:', calledBy('service').map((e) => line(nm(e.from))))
|
|
126
|
+
+ section('Called by endpoints:', calledBy('page').map((e) => line(nm(e.from))))
|
|
127
|
+
+ section('Pushes to (webhook):', edgesOf('delivers', 'from', node.id).map((e) => line(nm(e.to))));
|
|
112
128
|
}
|
|
113
129
|
if (node.type === 'page') {
|
|
114
130
|
const r = node.render;
|
|
115
|
-
const components = state.edges.filter((e) => e.dashed && e.from === node.id).map((e) => line(
|
|
116
|
-
return (node.methods ? section('Methods:', [line(
|
|
117
|
-
+ (node.render_fn ? section('Rendered by:', [line(
|
|
118
|
-
+ section('Calls outside:', edgesOf('calls', 'from', node.id).map((e) => line(
|
|
119
|
-
+ section('Pushed to by:', edgesOf('delivers', 'to', node.id).map((e) => line(
|
|
120
|
-
+ section('Starts:', edgesOf('triggers', 'from', node.id).map((e) => line(
|
|
131
|
+
const components = state.edges.filter((e) => e.dashed && e.from === node.id).map((e) => line(nm(e.to)));
|
|
132
|
+
return (node.methods ? section('Methods:', [line(node.methods.map(code).join(' '))]) : '')
|
|
133
|
+
+ (node.render_fn ? section('Rendered by:', [line(`${code(node.render_fn)} · ${escHtml(node.file)}`)]) : '')
|
|
134
|
+
+ section('Calls outside:', edgesOf('calls', 'from', node.id).map((e) => line(nm(e.to))))
|
|
135
|
+
+ section('Pushed to by:', edgesOf('delivers', 'to', node.id).map((e) => line(`${nm(e.from)} · ${escHtml(e.label)}`)))
|
|
136
|
+
+ section('Starts:', edgesOf('triggers', 'from', node.id).map((e) => line(`${nm(e.to)} · ${escHtml(e.label)}`)))
|
|
121
137
|
+ section('Renders:', components)
|
|
122
|
-
+ section('Reads:', reads.filter((e) => e.to === node.id).map((e) => line(
|
|
123
|
-
+ section('Writes:', writes.filter((e) => e.from === node.id).map((e) => line(
|
|
124
|
-
+ (r ? section('Render:', [line(
|
|
138
|
+
+ section('Reads:', reads.filter((e) => e.to === node.id).map((e) => line(`${nm(e.from)} · ${e.keys.map(code).join(' ')}`)))
|
|
139
|
+
+ section('Writes:', writes.filter((e) => e.from === node.id).map((e) => line(`${nm(e.to)} · ${escHtml(e.label)}`)))
|
|
140
|
+
+ (r ? section('Render:', [line(`today: ${code(r.now)} · ROM: ${r.rom === 'bake' ? '<span class="hx-rom hx-bold">bake</span>' : '<span class="hx-faint">skip (per request)</span>'}${r.note ? `<div class="hx-faint">${escHtml(r.note)}</div>` : ''}`)]) : '');
|
|
125
141
|
}
|
|
126
142
|
return '';
|
|
127
143
|
}
|
|
@@ -130,25 +146,71 @@ function dataSummary(node) {
|
|
|
130
146
|
// Threads that mention the node
|
|
131
147
|
// ---------------------------------------------------------------------------
|
|
132
148
|
|
|
133
|
-
/** "
|
|
149
|
+
/** "Threads": the threads whose text names the node (an idea, or a spec PR's conversation); each opens in the Work panel */
|
|
134
150
|
function threadsSection(node) {
|
|
135
151
|
const index = state.threadIndex;
|
|
136
152
|
if (!index) return '';
|
|
137
153
|
const threads = index.for(node.id);
|
|
138
154
|
// "Start a thread about this" shows whenever threads are on and a maintainer is signed in (the panel only sets `start` then)
|
|
139
|
-
const start = index.start ? `<
|
|
155
|
+
const start = index.start ? `<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-thread-start="${escHtml(node.id)}" aria-label="Start a thread about this: opens the New idea form for ${escHtml(index.forge())}, with this node mentioned">Start a thread about this</button>` : '';
|
|
140
156
|
if (!threads || !threads.length) return start;
|
|
141
|
-
const rows = threads.map((
|
|
142
|
-
|
|
157
|
+
const rows = threads.map((th) => {
|
|
158
|
+
const count = Number(th.comments) || 0;
|
|
159
|
+
return `<li><button type="button" class="hx-row hx-thread-open" data-thread-open="${escHtml(th.number)}" data-corn="row" aria-label="Open thread #${escHtml(th.number)}, ${escHtml(th.title)}, ${count} ${count === 1 ? 'comment' : 'comments'}, in the issues and pull requests panel"><span class="hx-row-title">${escHtml(th.title)}</span><span class="hx-row-meta">#${escHtml(th.number)} · ${count}</span></button></li>`;
|
|
160
|
+
});
|
|
161
|
+
return `<div class="hx-sec-block" data-corn="section"><h3 class="hx-sec-title">Threads</h3><ul class="hx-rows">${rows.join('')}</ul>${start}</div>`;
|
|
143
162
|
}
|
|
144
163
|
|
|
145
|
-
/** Draws "
|
|
164
|
+
/** Draws "Threads" again in the open panel (the list was just read, or the map changed); nothing else in the panel moves */
|
|
146
165
|
export function repaintThreads() {
|
|
147
166
|
const box = $('drawer-threads');
|
|
148
167
|
if (!box || !state.selectedNode) return;
|
|
149
168
|
box.innerHTML = threadsSection(state.selectedNode);
|
|
150
169
|
}
|
|
151
170
|
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// The head: type · host, and what the open proposal does to the node
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
/** "Page", "Cloud", "Public web": the kind of node, in words */
|
|
176
|
+
function typeWords(node) {
|
|
177
|
+
if (node.type === 'external' && node.kind) return node.kind === 'web' ? 'Public web' : 'Cloud';
|
|
178
|
+
return node.type.charAt(0).toUpperCase() + node.type.slice(1);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The host a node answers on, when it has one */
|
|
182
|
+
function hostOf(node) {
|
|
183
|
+
if (node.url) { try { return new URL(node.url).host; } catch { /* not a URL: no host */ } }
|
|
184
|
+
return node.host || '';
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** "Added by Checkout": the pill for a node the open proposal touches; '' for one it leaves alone */
|
|
188
|
+
export function diffPillWords(node) {
|
|
189
|
+
const mark = node && node.mark;
|
|
190
|
+
if (!mark || mark === 'none') return '';
|
|
191
|
+
if (mark === 'edit') return `${node.editOp === 'removed' ? 'Removed' : 'Added'} by your edit`;
|
|
192
|
+
const title = state.proposal && typeof state.proposal.title === 'string' ? state.proposal.title : '';
|
|
193
|
+
return title ? `${MARK_WORDS[mark] || mark} by ${title}` : `${MARK_WORDS[mark] || mark} by this proposal`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** "In this proposal": the diff for a changed node as key/value rows (id, parent, edges +2; a change shows each field before and after) */
|
|
197
|
+
function diffSection(node) {
|
|
198
|
+
const kind = kindOfMark(node);
|
|
199
|
+
if (!diffPillWords(node)) return '';
|
|
200
|
+
const row = (k, v) => `<div class="hx-diff-k">${escHtml(k)}</div><div class="hx-diff-v">${v}</div>`;
|
|
201
|
+
const rows = [row('id', escHtml(node.id))];
|
|
202
|
+
const parent = state.edges.find((e) => !e.kind && !e.dashed && e.to === node.id);
|
|
203
|
+
if (parent) rows.push(row('parent', escHtml(parent.from)));
|
|
204
|
+
const touching = state.edges.filter((e) => e.from === node.id || e.to === node.id);
|
|
205
|
+
const added = touching.filter((e) => kindOfMark(e) === 'added').length;
|
|
206
|
+
const removed = touching.filter((e) => kindOfMark(e) === 'removed').length;
|
|
207
|
+
if (added || removed) rows.push(row('edges', escHtml([added ? `+${added}` : '', removed ? `−${removed}` : ''].filter(Boolean).join(' '))));
|
|
208
|
+
if (kind === 'changed') {
|
|
209
|
+
for (const r of fieldRows(node)) rows.push(row(r.field, `<span class="hx-change-before">${escHtml(r.before) || '<em>nothing</em>'}</span> <span aria-hidden="true">→</span><span class="hx-sr-only"> became </span> <span class="hx-change-after">${escHtml(r.after) || '<em>nothing</em>'}</span>`));
|
|
210
|
+
}
|
|
211
|
+
return `<div class="hx-sec-block" data-proposal-mark="${escHtml(node.mark)}" data-corn="section"><h3 class="hx-sec-title">In this proposal</h3>${node.why ? `<p class="hx-why">${escHtml(node.why)}</p>` : ''}<div class="hx-diff hx-diff--${escHtml(kind)}">${rows.join('')}</div></div>`;
|
|
212
|
+
}
|
|
213
|
+
|
|
152
214
|
// ---------------------------------------------------------------------------
|
|
153
215
|
// The drawer
|
|
154
216
|
// ---------------------------------------------------------------------------
|
|
@@ -164,58 +226,55 @@ export async function selectNode(node) {
|
|
|
164
226
|
touchScene();
|
|
165
227
|
render();
|
|
166
228
|
|
|
167
|
-
const propsList = $('drawer-props-list');
|
|
168
229
|
const metaList = $('drawer-meta-list');
|
|
230
|
+
if (!metaList.dataset.moreBound) { metaList.dataset.moreBound = '1'; metaList.addEventListener('click', (e) => { toggleCapped(e.target); }); }
|
|
169
231
|
const openBtn = $('drawer-open-btn');
|
|
232
|
+
const title = $('drawer-title');
|
|
170
233
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
$('drawer-
|
|
234
|
+
title.textContent = node.tag ? `<${node.tag}>` : node.label;
|
|
235
|
+
title.classList.toggle('hx-mono', node.type === 'page' || !!node.tag); // a route or a tag reads as code
|
|
236
|
+
$('drawer-badge').textContent = typeWords(node);
|
|
237
|
+
const host = hostOf(node);
|
|
238
|
+
$('drawer-host').textContent = host ? ` · ${host}` : '';
|
|
239
|
+
const pill = diffPillWords(node);
|
|
240
|
+
$('drawer-diff').textContent = pill;
|
|
241
|
+
$('drawer-diff').hidden = !pill;
|
|
242
|
+
const lead = $('drawer-description');
|
|
243
|
+
lead.textContent = node.desc || '';
|
|
244
|
+
lead.hidden = !node.desc;
|
|
174
245
|
if (token !== selectToken) return;
|
|
175
246
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
<div><strong class="hx-strong">Category:</strong> ${escHtml(node.type)}</div>
|
|
187
|
-
<div><strong class="hx-strong">Connected Edges:</strong> <span class="hx-accent hx-bold">${node.degree || 0}</span></div>
|
|
188
|
-
${node.file ? `<div><strong class="hx-strong">File:</strong> <code class="hx-code">${escHtml(node.file)}</code></div>` : ''}
|
|
189
|
-
${flowSummary(node)}
|
|
190
|
-
${dataSummary(node)}`;
|
|
247
|
+
const facts = `${node.file ? section('File', [code(node.file)]) : ''}${flowSummary(node)}${dataSummary(node)}`;
|
|
248
|
+
metaList.innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
249
|
+
<div id="drawer-live">${liveSection(node)}</div>
|
|
250
|
+
${nodeMockupsHtml(node.id)}
|
|
251
|
+
<div id="drawer-threads">${threadsSection(node)}</div>
|
|
252
|
+
${diffSection(node)}`;
|
|
253
|
+
if (state.threadIndex) state.threadIndex.ensure();
|
|
254
|
+
hydrateLivePhotos($('drawer-live'));
|
|
255
|
+
|
|
256
|
+
// The actions: Open (when the node has an address) is the primary one; Start a run, when the open proposal can be handed to an agent
|
|
191
257
|
if (node.url && /^https?:\/\//.test(node.url)) {
|
|
192
258
|
openBtn.href = node.url;
|
|
193
259
|
openBtn.textContent = `${t('openRoute')} ↗`;
|
|
260
|
+
openBtn.hidden = false;
|
|
194
261
|
} else {
|
|
195
262
|
openBtn.removeAttribute('href');
|
|
196
|
-
openBtn.
|
|
263
|
+
openBtn.hidden = true;
|
|
197
264
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const proposed = proposalPanelHtml(node);
|
|
201
|
-
if (proposed) metaList.insertAdjacentHTML('afterbegin', proposed);
|
|
202
|
-
// The screens the proposal lists for it, which open from here (mockups.js)
|
|
203
|
-
const mockups = nodeMockupsHtml(node.id);
|
|
204
|
-
if (mockups) (proposed ? metaList.firstElementChild : metaList).insertAdjacentHTML(proposed ? 'afterend' : 'afterbegin', mockups);
|
|
205
|
-
|
|
206
|
-
// The threads that mention it (docs/threads.md): filled in place once the list is read
|
|
207
|
-
metaList.insertAdjacentHTML('beforeend', `<div id="drawer-threads">${threadsSection(node)}</div>`);
|
|
208
|
-
if (state.threadIndex) state.threadIndex.ensure();
|
|
209
|
-
|
|
210
|
-
// What the live layer knows of it (spec 0029): a count, a linked machine's item, contents and sets; repainted in place by live.js
|
|
211
|
-
metaList.insertAdjacentHTML('beforeend', `<div id="drawer-live">${liveSection(node)}</div>`);
|
|
212
|
-
hydrateLivePhotos($('drawer-live'));
|
|
265
|
+
const run = $('drawer-run-btn');
|
|
266
|
+
run.hidden = !(state.proposalSlug && canStartAgent());
|
|
213
267
|
|
|
214
268
|
$('spec-drawer').classList.add('drawer-open');
|
|
215
269
|
$('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
|
|
216
270
|
$('drawer-backdrop').hidden = false;
|
|
217
271
|
}
|
|
218
272
|
|
|
273
|
+
/** Start a run: the Start dialog of the Work panel, on the proposal that is open */
|
|
274
|
+
export function startRun() {
|
|
275
|
+
if (state.proposalSlug) openProposalStart(state.proposalSlug, '#drawer-run-btn');
|
|
276
|
+
}
|
|
277
|
+
|
|
219
278
|
export function closeDrawer() {
|
|
220
279
|
selectToken++;
|
|
221
280
|
state.selectedEdge = null;
|
package/explorer/plugins.js
CHANGED
|
@@ -69,13 +69,32 @@ function applyBrand(doc, brand, title) {
|
|
|
69
69
|
if (heading && brand.appName) heading.textContent = `${brand.appName}: the map`;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** The
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
/** The footer line of the account menu: "powered by cornfield 0.14.0". A link to cornfield when the brand names where it leads */
|
|
73
|
+
function paintFooter(doc, config) {
|
|
74
|
+
const foot = doc.getElementById('cf-powered');
|
|
75
|
+
if (!foot) return;
|
|
76
|
+
const words = [t('poweredBy'), typeof config.version === 'string' ? config.version : ''].filter(Boolean).join(' ');
|
|
77
|
+
const home = config.brand && typeof config.brand.poweredBy === 'string' && /^https:\/\//.test(config.brand.poweredBy) ? config.brand.poweredBy : '';
|
|
78
|
+
foot.innerHTML = home ? `<a href="${escHtml(home)}" target="_blank" rel="noreferrer">${escHtml(words)}</a>` : escHtml(words);
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
const FORGE_NAMES = { github: 'GitHub', forgejo: 'Forgejo' };
|
|
82
|
+
|
|
83
|
+
/** The link rows of the account menu: the config's links, the forge (unless a link already leads there), and cornfield's docs */
|
|
84
|
+
function linkRows(config) {
|
|
85
|
+
const rows = (Array.isArray(config.links) ? config.links : [])
|
|
86
|
+
.filter((l) => l && typeof l.label === 'string' && /^(https?:\/\/|\/)/.test(String(l.href)))
|
|
87
|
+
.map((l) => ({ label: l.label, href: l.href }));
|
|
88
|
+
const forge = config.forge;
|
|
89
|
+
if (forge && typeof forge.url === 'string' && /^https:\/\//.test(forge.url) && typeof forge.repo === 'string') {
|
|
90
|
+
const href = `${forge.url.replace(/\/+$/, '')}/${forge.repo}`;
|
|
91
|
+
if (!rows.some((r) => r.href === href || String(r.href).startsWith(`${href}/`))) rows.push({ label: FORGE_NAMES[forge.type] || 'Forge', href });
|
|
92
|
+
}
|
|
93
|
+
if (typeof config.docs === 'string' && /^https:\/\//.test(config.docs)) rows.push({ label: 'Docs', href: config.docs });
|
|
94
|
+
return rows.map((r) => `<a class="hx-account-item" href="${escHtml(r.href)}" target="_blank" rel="noreferrer" data-corn="link"><span>${escHtml(r.label)}</span><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M6 3h7v7M13 3L7 9" /></svg></a>`).join('');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Puts the repo's title, brand and links in the header, and who is signed in, with Sign out, in the account menu */
|
|
79
98
|
export function applyBranding(doc, config) {
|
|
80
99
|
if (!config || !doc) return;
|
|
81
100
|
// The repo's words (core/strings.js) first: what is built below reads them, and the static markup is filled now
|
|
@@ -87,19 +106,30 @@ export function applyBranding(doc, config) {
|
|
|
87
106
|
if (heading && config.title) heading.textContent = `${config.title}: the map`;
|
|
88
107
|
if (config.brand) applyBrand(doc, config.brand, config.title);
|
|
89
108
|
initThemePicker(doc, config.theme);
|
|
109
|
+
paintAccount(doc, config);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The account button's initial, the line saying who is signed in, the links, Sign out and the footer */
|
|
113
|
+
function paintAccount(doc, config) {
|
|
114
|
+
const login = config.signIn && typeof config.signIn.login === 'string' ? config.signIn.login : '';
|
|
115
|
+
const initial = doc.getElementById('account-initial');
|
|
116
|
+
if (initial) initial.textContent = login ? [...login][0].toUpperCase() : '';
|
|
117
|
+
const btn = doc.getElementById('account-btn');
|
|
118
|
+
if (btn) btn.setAttribute('aria-label', login ? `Account menu, signed in as ${login}` : 'Account menu');
|
|
119
|
+
const who = doc.getElementById('account-who');
|
|
120
|
+
if (who) {
|
|
121
|
+
who.hidden = !login;
|
|
122
|
+
// Only a maintainer gets past the sign-in (server/auth.js), so whoever is here is one
|
|
123
|
+
who.textContent = login ? `${login} · maintainer` : '';
|
|
124
|
+
}
|
|
125
|
+
paintFooter(doc, config);
|
|
90
126
|
const links = doc.getElementById('cf-links');
|
|
91
127
|
if (!links) return;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.join('') : '';
|
|
96
|
-
// A plain form: signing out is a same-origin POST (server/auth.js), no script needed. On a narrow phone only its icon
|
|
97
|
-
// shows (explorer.css); the words stay in the button for a screen reader
|
|
98
|
-
const signOut = config.signIn && typeof config.signIn.login === 'string'
|
|
99
|
-
? `<form class="cf-sign-out" method="post" action="/auth/sign-out" data-corn="sign-out"><button type="submit" class="hx-btn hx-btn--quiet" title="Signed in as ${escHtml(config.signIn.login)}" data-corn-kind="quiet"><span class="cf-sign-out-icon" aria-hidden="true">⎋</span><span class="cf-sign-out-text">${escHtml(t('signOut'))}</span></button></form>`
|
|
128
|
+
// A plain form: signing out is a same-origin POST (server/auth.js), no script needed
|
|
129
|
+
const signOut = login
|
|
130
|
+
? `<form class="cf-sign-out" method="post" action="/auth/sign-out" data-corn="sign-out"><button type="submit" class="hx-account-item" title="Signed in as ${escHtml(login)}" data-corn-kind="quiet">${escHtml(t('signOut'))}</button></form>`
|
|
100
131
|
: '';
|
|
101
|
-
|
|
102
|
-
if (html || powered || signOut) links.innerHTML = html + powered + signOut;
|
|
132
|
+
links.innerHTML = linkRows(config) + signOut;
|
|
103
133
|
}
|
|
104
134
|
|
|
105
135
|
/**
|
package/explorer/proposal.js
CHANGED
|
@@ -462,18 +462,23 @@ export function markedEdgeAt(x, y, tolerance) {
|
|
|
462
462
|
export function showEdgePanel(edge) {
|
|
463
463
|
closeDrawer(); // clears a node selection and any panel still loading
|
|
464
464
|
state.selectedEdge = edge;
|
|
465
|
-
const row = (label, value) => (value ? `<div class="hx-
|
|
465
|
+
const row = (label, value) => (value ? `<div class="hx-fact"><div class="hx-fact-k">${escHtml(label)}</div><div class="hx-fact-v">${escHtml(value)}</div></div>` : '');
|
|
466
|
+
const facts = row('Kind', kindOf(edge)) + row('Flow', edge.flow) + row('Label', edge.label) + row('Reads', Array.isArray(edge.keys) ? edge.keys.join(', ') : '');
|
|
466
467
|
|
|
467
468
|
$('drawer-title').textContent = `${nameOf(edge.from)} → ${nameOf(edge.to)}`;
|
|
468
|
-
$('drawer-
|
|
469
|
-
$('drawer-
|
|
470
|
-
$('drawer-
|
|
471
|
-
$('drawer-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
469
|
+
$('drawer-title').classList.remove('hx-mono');
|
|
470
|
+
$('drawer-badge').textContent = 'Edge';
|
|
471
|
+
$('drawer-host').textContent = '';
|
|
472
|
+
$('drawer-diff').hidden = true;
|
|
473
|
+
$('drawer-description').textContent = '';
|
|
474
|
+
$('drawer-description').hidden = true;
|
|
475
|
+
$('drawer-meta-list').innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
476
|
+
<div class="hx-facts">
|
|
477
|
+
<div class="hx-fact"><div class="hx-fact-k">From</div><div class="hx-fact-v"><button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.from)}">${escHtml(nameOf(edge.from))}</button></div></div>
|
|
478
|
+
<div class="hx-fact"><div class="hx-fact-k">To</div><div class="hx-fact-v"><button type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.to)}">${escHtml(nameOf(edge.to))}</button></div></div>
|
|
479
|
+
</div>${proposalPanelHtml(edge)}`;
|
|
480
|
+
$('drawer-open-btn').hidden = true;
|
|
481
|
+
$('drawer-run-btn').hidden = true;
|
|
477
482
|
$('spec-drawer').classList.add('drawer-open');
|
|
478
483
|
$('drawer-backdrop').hidden = false;
|
|
479
484
|
touchScene();
|
package/explorer/render.js
CHANGED
|
@@ -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
|
-
|
|
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) {
|
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 "
|
|
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
|
|
package/explorer/theme-model.js
CHANGED
|
@@ -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
|
|
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,
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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));
|