cornfield 0.41.0 → 0.43.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/contrast.js +68 -2
- package/core/delta-e.js +66 -0
- package/core/schema.js +29 -7
- package/core/strings.js +11 -0
- package/explorer/capped.js +6 -5
- package/explorer/cloud-model.js +10 -7
- package/explorer/decision-model.js +231 -0
- package/explorer/diff-marks.js +3 -1
- package/explorer/edge-key.js +59 -0
- package/explorer/explorer.css +55 -9
- package/explorer/flows.js +0 -2
- package/explorer/forge-panel.js +30 -8
- package/explorer/glyphs.js +130 -0
- package/explorer/house-model.js +2 -2
- package/explorer/index.html +7 -18
- package/explorer/keyboard-model.js +4 -1
- package/explorer/keyboard.js +14 -2
- package/explorer/kind-letters.js +9 -5
- package/explorer/labels.js +33 -34
- package/explorer/layers.js +16 -5
- package/explorer/main.js +3 -2
- package/explorer/map-style.js +3 -0
- package/explorer/panels.js +92 -7
- package/explorer/proposal-model.js +24 -0
- package/explorer/proposal.js +13 -6
- package/explorer/render.js +2 -2
- package/explorer/renderer-canvas2d.js +169 -26
- package/explorer/renderer-webgl.js +51 -17
- package/explorer/review-column.js +22 -4
- package/explorer/review.js +413 -44
- package/explorer/runs-model.js +1 -1
- package/explorer/scene.js +58 -47
- package/explorer/selection-model.js +150 -0
- package/explorer/selection-view.js +36 -0
- package/explorer/shaders.js +76 -13
- package/explorer/spatial.js +7 -4
- package/explorer/state.js +8 -0
- package/explorer/tokens.css +1 -0
- package/explorer/whatif.js +84 -7
- package/package.json +1 -1
- package/server/decision.js +117 -0
- package/server/proposal-pulls.js +1 -1
- package/server/proposals.js +58 -9
- package/server/server.js +19 -2
- package/server/submit-review.js +52 -7
package/explorer/labels.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* A label is never drawn under 11 px (a hub's, 13 px, bold; a theme may raise the 11 with `--corn-map-label-min`): text that
|
|
19
19
|
* would be smaller is not drawn smaller, it competes for room at 11 px. Zoomed in, it grows with the map.
|
|
20
20
|
* A node left without a label is named by a chip over everything else while the pointer is on it (`hover`).
|
|
21
|
-
* Lane titles, notes and arrows and the selection's
|
|
21
|
+
* Lane titles, notes and arrows are always included and take no part in the placing. The kind words on a selection's lit edges (spec 0008 D7) are placed last, after every node label: a word is drawn only where it touches no node label, no lit node's disc and no word before it.
|
|
22
22
|
* The layer redraws only when the camera, the scene, the size or the hover changed, so a packet frame (the renderer
|
|
23
23
|
* redrawing for animation) costs the labels nothing.
|
|
24
24
|
*
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* never the explorer's state.
|
|
27
27
|
*
|
|
28
28
|
* @typedef {object} LabelItem One piece of text to draw
|
|
29
|
-
* @property {'node'|'edge'|'lane'|'chip'} kind
|
|
29
|
+
* @property {'node'|'edge'|'lane'|'chip'} kind `edge`: a kind word on a lit edge, in screen space
|
|
30
30
|
* @property {string} [id] the node, for `kind: 'node'` and `'chip'`
|
|
31
31
|
* @property {string} text
|
|
32
32
|
* @property {number} x world coordinates; the text is drawn on this baseline point
|
|
@@ -44,11 +44,13 @@
|
|
|
44
44
|
* @property {boolean} [screen] a node's label at its minimum size: drawn in screen space at `px`, so the font stays one string while the zoom changes (a changing font string is the slow part of drawing text)
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
|
-
import {
|
|
47
|
+
import { FONT_EDGE, FONT_NODE, HUB_LABEL_EXTRA_PX, LABEL_MIN_FLOOR, LABEL_MIN_PX, LANDMARK_TYPES, looksFor } from './scene.js';
|
|
48
48
|
import { getMapStyle, styledScene } from './map-style.js';
|
|
49
49
|
|
|
50
50
|
/** At most this many node labels in view at a time (lane text and selection edge labels are extra); the placing itself never needs it */
|
|
51
51
|
export const MAX_LABELS = 400;
|
|
52
|
+
/** At most this many kind words on the lit edges in view (spec 0008 D7) */
|
|
53
|
+
export const MAX_EDGE_WORDS = 120;
|
|
52
54
|
/** A label this many screen px past the viewport is still kept, so none pops in at the border */
|
|
53
55
|
export const CULL_MARGIN = 32;
|
|
54
56
|
/** A label whose box, this many px bigger on every side, touches a placed one is skipped: placed labels are at least this far apart */
|
|
@@ -162,7 +164,7 @@ export function placeLabels(scene, zoom, opts = {}) {
|
|
|
162
164
|
* `max` node labels in view (default 400); `margin` px past the viewport (default 32); `measure` the width of a text at a font
|
|
163
165
|
* size (default: an estimate from its length); `hover`: the node the pointer is on, named by a chip when it has no label;
|
|
164
166
|
* `placed`: the placing for this scene at this zoom, when the caller has kept it (default: made here)
|
|
165
|
-
* @returns {LabelItem[]} lane text, then
|
|
167
|
+
* @returns {LabelItem[]} lane text, then node labels in scene order, then the words on the lit edges, then the chip
|
|
166
168
|
*/
|
|
167
169
|
export function chooseLabels(scene, camera, viewport, opts = {}) {
|
|
168
170
|
const { max = MAX_LABELS, margin = CULL_MARGIN, measure = null, hover = null } = opts;
|
|
@@ -175,12 +177,6 @@ export function chooseLabels(scene, camera, viewport, opts = {}) {
|
|
|
175
177
|
if (t) out.push({ kind: 'lane', text: t.text, x: t.x, y: t.y, size: t.size, bold: t.bold, italic: false, color: t.color, alpha: 1, outline: null, align: 'center', family: scene.labelFont || FONT_NODE });
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
|
-
// ... and the labels on the selection's edges
|
|
179
|
-
for (const edge of scene.edges) {
|
|
180
|
-
const l = edge.label;
|
|
181
|
-
if (l) out.push({ kind: 'edge', text: l.text, x: l.x, y: l.y, size: EDGE_LABEL_SIZE, bold: false, italic: !!l.italic, color: l.color, alpha: edge.alpha, outline: outline.edge, align: 'center', family: scene.labelFont || FONT_EDGE });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
180
|
// Node labels: the placing for this zoom, then the boxes that reach the viewport
|
|
185
181
|
const { zoom } = camera;
|
|
186
182
|
const placed = opts.placed || placeLabels(scene, zoom, { measure });
|
|
@@ -196,6 +192,30 @@ export function chooseLabels(scene, camera, viewport, opts = {}) {
|
|
|
196
192
|
out.push({ kind: 'node', id: p.id, text: p.node.label, x: p.x, y: p.y, size: p.size, bold: p.bold, italic: false, color: p.node.labelColor, alpha: p.node.labelAlpha, outline: outline.node ? { color: outline.node.color, width: outline.node.width * k } : null, align: 'center', family, strike: !!p.node.labelStrike, px: p.px, screen: p.screen });
|
|
197
193
|
}
|
|
198
194
|
|
|
195
|
+
// The words on the lit edges ("reads", "calls": spec 0008 D7) go last, below every node label: one is placed only where it touches no node label, no lit
|
|
196
|
+
// node's disc and no word placed before it, so it never covers a name; at the label minimum size, in screen space
|
|
197
|
+
const px = labelMinOf(scene);
|
|
198
|
+
const taken = inView.map((p) => ({ l: camera.x + p.l, r: camera.x + p.r, t: camera.y + p.t, b: camera.y + p.b }));
|
|
199
|
+
for (const n of scene.nodes) {
|
|
200
|
+
if (n.alpha < 0.5) continue;
|
|
201
|
+
const cx = camera.x + n.x * zoom, cy = camera.y + n.y * zoom, rr = n.r * zoom;
|
|
202
|
+
if (cx + rr < 0 || cx - rr > viewport.width || cy + rr < 0 || cy - rr > viewport.height) continue;
|
|
203
|
+
taken.push({ l: cx - rr, r: cx + rr, t: cy - rr, b: cy + rr });
|
|
204
|
+
}
|
|
205
|
+
let words = 0;
|
|
206
|
+
for (const edge of scene.edges) {
|
|
207
|
+
const l = edge.label;
|
|
208
|
+
if (!l || words >= MAX_EDGE_WORDS) continue;
|
|
209
|
+
const sx = camera.x + l.x * zoom, sy = camera.y + l.y * zoom;
|
|
210
|
+
if (sx < 0 || sx > viewport.width || sy < 0 || sy > viewport.height) continue;
|
|
211
|
+
const w = (measure ? measure(l.text, px, false) : l.text.length * px * 0.55) / 2 + LABEL_PAD;
|
|
212
|
+
const box = { l: sx - w, r: sx + w, t: sy - px * 0.6 - LABEL_PAD, b: sy + px * 0.6 + LABEL_PAD };
|
|
213
|
+
if (taken.some((o) => box.l < o.r && box.r > o.l && box.t < o.b && box.b > o.t)) continue;
|
|
214
|
+
taken.push(box);
|
|
215
|
+
words++;
|
|
216
|
+
out.push({ kind: 'edge', text: l.text, x: l.x, y: l.y + (px * 0.35) / zoom, size: px / zoom, px, screen: true, bold: false, italic: !!l.italic, color: l.color, alpha: edge.alpha, outline: outline.edge, align: 'center', family: scene.labelFont || FONT_EDGE });
|
|
217
|
+
}
|
|
218
|
+
|
|
199
219
|
// The chip: a node with no label, named while the pointer is on it
|
|
200
220
|
if (hover) {
|
|
201
221
|
const node = scene.nodes.find((n) => n.id === hover);
|
|
@@ -271,26 +291,6 @@ function drawItem(ctx, t, pen, v = WORLD) {
|
|
|
271
291
|
}
|
|
272
292
|
}
|
|
273
293
|
|
|
274
|
-
/**
|
|
275
|
-
* Erases every node circle from what is drawn so far. The map used to draw an edge's label before
|
|
276
|
-
* the circles, so a node covered it; this layer is above the circles, so it cuts them out of the
|
|
277
|
-
* lane and edge text instead (a dimmed node, which hides almost nothing, does not cut).
|
|
278
|
-
*/
|
|
279
|
-
function coverWithNodes(ctx, nodes) {
|
|
280
|
-
ctx.save();
|
|
281
|
-
ctx.globalCompositeOperation = 'destination-out';
|
|
282
|
-
ctx.globalAlpha = 1;
|
|
283
|
-
ctx.fillStyle = '#000';
|
|
284
|
-
ctx.beginPath();
|
|
285
|
-
nodes.forEach((n) => {
|
|
286
|
-
if (n.alpha < 0.5) return;
|
|
287
|
-
ctx.moveTo(n.x + n.r, n.y);
|
|
288
|
-
ctx.arc(n.x, n.y, n.r, 0, Math.PI * 2);
|
|
289
|
-
});
|
|
290
|
-
ctx.fill();
|
|
291
|
-
ctx.restore();
|
|
292
|
-
}
|
|
293
|
-
|
|
294
294
|
/**
|
|
295
295
|
* The placed label under a screen point, or null: the one drawn on top (the last in scene order) when two overlap their padding
|
|
296
296
|
* @param {ReturnType<typeof placeLabels>} placed
|
|
@@ -375,11 +375,9 @@ export function createLabelLayer(canvas, opts = {}) {
|
|
|
375
375
|
// The placing is for the whole map at this zoom: kept while the scene, the zoom and the style stay (a pan, a hover), made again when one changes
|
|
376
376
|
if (!samePlacing) kept = placeLabels(scene, camera.zoom, { measure });
|
|
377
377
|
const items = chooseLabels(scene, camera, { width, height }, { measure, hover, placed: kept });
|
|
378
|
-
// The lane text
|
|
378
|
+
// The lane text (the words on the lit edges are placed below the node labels, and drawn with them in screen space, below)
|
|
379
379
|
let pen = newPen();
|
|
380
|
-
|
|
381
|
-
for (const t of items) { if (t.kind === 'lane' || t.kind === 'edge') { drawItem(ctx, t, pen); if (t.kind === 'edge') edges = true; } }
|
|
382
|
-
if (edges) { coverWithNodes(ctx, scene.nodes); pen = newPen(); }
|
|
380
|
+
for (const t of items) if (t.kind === 'lane') drawItem(ctx, t, pen);
|
|
383
381
|
for (const t of items) if (t.kind === 'node' && !t.screen) drawItem(ctx, t, pen); // a label that grows with the map: the camera's transform
|
|
384
382
|
ctx.restore();
|
|
385
383
|
// A label at its minimum size is drawn in screen space at a whole font size, whatever the zoom: the font string does not change as the
|
|
@@ -387,6 +385,7 @@ export function createLabelLayer(canvas, opts = {}) {
|
|
|
387
385
|
const screen = { ox: camera.x, oy: camera.y, k: camera.zoom };
|
|
388
386
|
pen = newPen();
|
|
389
387
|
for (const t of items) if (t.kind === 'node' && t.screen) drawItem(ctx, t, pen, screen);
|
|
388
|
+
for (const t of items) if (t.kind === 'edge') drawItem(ctx, t, pen, screen); // the kind words: where no node label, disc or word is
|
|
390
389
|
for (const t of items) if (t.kind === 'chip') drawItem(ctx, t, pen, screen);
|
|
391
390
|
return true;
|
|
392
391
|
},
|
package/explorer/layers.js
CHANGED
|
@@ -10,19 +10,23 @@ import { state, touchScene, escHtml } from './state.js';
|
|
|
10
10
|
import { render, ensureFlowLoop, isNodeVisible } from './render.js';
|
|
11
11
|
import { renderFlowLegend } from './flows.js';
|
|
12
12
|
import { WHEN_STYLES } from './cloud-model.js';
|
|
13
|
+
import { edgeKeyHtml, keySwatch } from './edge-key.js';
|
|
13
14
|
import { themed } from './theme-model.js';
|
|
14
15
|
import { onThemeChange } from './theme.js';
|
|
16
|
+
import { NODE_THEMES } from '../core/schema.js';
|
|
15
17
|
import { STARTING_LAYERS, clientLayers, kindLetters, orderRows, startingLayerOf } from '../core/layers.js';
|
|
16
18
|
import { rowKeyOf, shownByProposal } from './layer-model.js';
|
|
17
19
|
import { layerShows } from './scene.js';
|
|
18
20
|
import { getMapStyle, groupToken, setMapSubjects } from './map-style.js';
|
|
19
21
|
import { t } from './strings.js';
|
|
20
22
|
|
|
21
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* The dot of each starting row: the colour its nodes are drawn in, read from the node types' own colours (core/schema.js), so the dots and
|
|
25
|
+
* the map cannot drift apart when the palette moves (a project layer's dot is its nodes' own, or the theme's group token)
|
|
26
|
+
*/
|
|
22
27
|
const COLORS = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
machine: '#78716c', container: '#d6d3d1', device: '#2dd4bf', house: '#a3e635', runs: '#5eead4', persona: '#fb7185',
|
|
28
|
+
...Object.fromEntries(Object.entries(NODE_THEMES).map(([type, { color }]) => [type, color])),
|
|
29
|
+
flow: NODE_THEMES.store.color, cloud: NODE_THEMES.external.color, web: NODE_THEMES.external.color, house: NODE_THEMES.floor.color, runs: '#5eead4',
|
|
26
30
|
};
|
|
27
31
|
/** The starting layers that start off: the infra layer is its own view, and the physical world's are loaded when first turned on (spec 0029) */
|
|
28
32
|
const STARTS_OFF = new Set(['stack', 'machine', 'container', 'device', 'house', 'persona']);
|
|
@@ -272,9 +276,16 @@ export function renderLayerToggles() {
|
|
|
272
276
|
if (again && typeof again.focus === 'function') again.focus({ preventScroll: true });
|
|
273
277
|
}
|
|
274
278
|
renderFlowLegend();
|
|
279
|
+
renderEdgeKey();
|
|
275
280
|
renderCloudLegend();
|
|
276
281
|
}
|
|
277
282
|
|
|
283
|
+
/** The Key (spec 0008 D7): each kind of line as the map draws it (edge-key.js) */
|
|
284
|
+
export function renderEdgeKey() {
|
|
285
|
+
const el = document.getElementById('edge-key');
|
|
286
|
+
if (el) el.innerHTML = edgeKeyHtml();
|
|
287
|
+
}
|
|
288
|
+
|
|
278
289
|
/** What a call into a cloud node looks like for its `when` (spec 0031 section 6), while the Cloud layer is on */
|
|
279
290
|
export function renderCloudLegend() {
|
|
280
291
|
const el = document.getElementById('cloud-legend');
|
|
@@ -283,7 +294,7 @@ export function renderCloudLegend() {
|
|
|
283
294
|
el.hidden = false;
|
|
284
295
|
el.innerHTML = `
|
|
285
296
|
<div class="hx-menu-title" data-corn="menu-title"><span>Cloud: when an outage bites</span></div>
|
|
286
|
-
${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch
|
|
297
|
+
${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch hx-legend-swatch--wide hx-swatch-when--${when}">${keySwatch({ end: 'triangle', ticks: s.ticks })}</span><span>${s.legend}</span></div>`).join('')}
|
|
287
298
|
<div class="hx-legend-row"><span class="hx-legend-swatch"></span><span class="hx-faint"><span class="hx-cloud-browser">(browser)</span> the visitor's browser makes the call, not our server</span></div>`;
|
|
288
299
|
}
|
|
289
300
|
|
package/explorer/main.js
CHANGED
|
@@ -46,7 +46,7 @@ import { initLive } from './live.js';
|
|
|
46
46
|
import { initHouse } from './house.js';
|
|
47
47
|
import { houseOffered } from './house-model.js';
|
|
48
48
|
import { initChecks } from './check.js';
|
|
49
|
-
import { initKeyboard } from './keyboard.js';
|
|
49
|
+
import { frameThem, initKeyboard } from './keyboard.js';
|
|
50
50
|
import { initForgePanel } from './forge-panel.js';
|
|
51
51
|
import { initReviewTokens } from './review-tokens.js';
|
|
52
52
|
import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
|
|
@@ -128,7 +128,8 @@ const ACTIONS = {
|
|
|
128
128
|
'close-drawer': () => closeDrawer(),
|
|
129
129
|
'copy-spec': (el) => copySpec(el),
|
|
130
130
|
'start-run': () => startRun(),
|
|
131
|
-
'select-node': (el) => selectNode(nodeById(el.dataset.id)),
|
|
131
|
+
'select-node': (el) => selectNode(nodeById(el.dataset.id), { frame: true }), // a link or a list row: the camera follows (spec 0008 D6)
|
|
132
|
+
'frame-selection': () => frameThem(),
|
|
132
133
|
'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
|
|
133
134
|
'retry': () => loadTopology(),
|
|
134
135
|
'set-theme': (el) => setThemeChoice(el.dataset.choice),
|
package/explorer/map-style.js
CHANGED
|
@@ -55,6 +55,8 @@ export const FONT_TOKEN = '--corn-map-font';
|
|
|
55
55
|
export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
|
|
56
56
|
export const GLOW_TOKEN = '--corn-map-glow';
|
|
57
57
|
export const LABEL_MIN_TOKEN = '--corn-map-label-min';
|
|
58
|
+
/** The ink of a node's glyph and of a finer kind's letters (spec 0008 D8); `auto` is the white or the dark that reads on the node's fill (glyphs.js) */
|
|
59
|
+
export const GLYPH_TOKEN = '--corn-map-glyph';
|
|
58
60
|
/** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
|
|
59
61
|
export const MAX_LABEL_MIN = 24;
|
|
60
62
|
/** The width an ordinary line has with no theme (scene.js `flowEdge`): the `--corn-map-edge-width` scales every line by its ratio to this */
|
|
@@ -86,6 +88,7 @@ export const MAP_COLOR_TOKENS = Object.freeze([
|
|
|
86
88
|
STROKE_TOKEN,
|
|
87
89
|
LABEL_TOKEN,
|
|
88
90
|
LABEL_HALO_TOKEN,
|
|
91
|
+
GLYPH_TOKEN,
|
|
89
92
|
...MAP_EDGE_KINDS.map(edgeToken),
|
|
90
93
|
...MAP_MARKS.map(stateToken),
|
|
91
94
|
...MAP_STATES.map(stateToken),
|
package/explorer/panels.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* cloud node (spec 0031) its plan, what breaks if it is down and who uses it, by when (cloud-model.js).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { state, nodeById, nameOf, escHtml, touchScene } from './state.js';
|
|
10
|
-
import { render } from './render.js';
|
|
9
|
+
import { state, nodeById, nameOf, escHtml, touchScene, viewEdges } from './state.js';
|
|
10
|
+
import { render, onPaint } from './render.js';
|
|
11
11
|
import { flowSummary } from './flows.js';
|
|
12
12
|
import { clearScenario } from './scenario-ui.js';
|
|
13
13
|
import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
|
|
@@ -23,6 +23,9 @@ import { capped, toggleCapped } from './capped.js';
|
|
|
23
23
|
import { dismissHint } from './hint.js';
|
|
24
24
|
import { canStartAgent, openProposalStart } from './forge-panel.js';
|
|
25
25
|
import { sayResult, clearResult, showResultIn, RESULT_MS } from './feedback.js';
|
|
26
|
+
import { activeSubgraph, connectedLine, farEnds, kindPanelWord, linesByKind } from './selection-model.js';
|
|
27
|
+
import { frameSelection, reach } from './selection-view.js';
|
|
28
|
+
import { announce } from './keyboard.js';
|
|
26
29
|
|
|
27
30
|
const $ = (id) => document.getElementById(id);
|
|
28
31
|
|
|
@@ -220,24 +223,105 @@ function diffSection(node) {
|
|
|
220
223
|
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)}" data-corn="diff-block"${markStateAttr(node.mark)}>${rows.join('')}</div></div>`;
|
|
221
224
|
}
|
|
222
225
|
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// What the selection lights: the lines by kind, the switch, Frame them (spec 0008 D5 and D6)
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
/** The most rows a kind's list shows before "and N more" */
|
|
231
|
+
export const LINES_CAP = 12;
|
|
232
|
+
|
|
233
|
+
/** The lit set the panel describes: the same rule the scene lights by (selection-model.js) */
|
|
234
|
+
const litNow = () => activeSubgraph(state.selectedNode, viewEdges(), { throughChildren: state.throughChildren, kind: state.selectedKind });
|
|
235
|
+
|
|
236
|
+
/** The panel's "Calls 12 · Reads 9" chips, the chosen kind's far ends, the switch, and the line that says how much is on screen, with Frame them */
|
|
237
|
+
function linesHtml(node) {
|
|
238
|
+
const sub = litNow();
|
|
239
|
+
if (!sub || !sub.kinds.size) return '';
|
|
240
|
+
const kinds = linesByKind(sub);
|
|
241
|
+
const chips = kinds.map(({ kind, count, word }) => `<button type="button" class="hx-lines-kind" data-corn="lines-kind" data-corn-kind="quiet" data-lines-kind="${escHtml(kind)}" data-focus-key="kind:${escHtml(kind)}" aria-pressed="${sub.kind === kind}">${escHtml(word)} <span class="hx-lines-count" data-corn="count">${count}</span></button>`).join('');
|
|
242
|
+
const open = sub.kind ? farEnds(sub, sub.kind).map((r) => `<button type="button" class="hx-linkbtn" data-corn="node-link" data-action="select-node" data-id="${escHtml(r.id)}"><span class="hx-sr-only">${r.out ? 'to ' : 'from '}</span><span aria-hidden="true">${r.out ? '→' : '←'}</span> ${escHtml(nameOf(r.id))}</button>`) : [];
|
|
243
|
+
const list = open.length ? `<div class="hx-lines-list">${capped(open, LINES_CAP)}</div>` : '';
|
|
244
|
+
const hasChildren = activeSubgraph(node, viewEdges(), { throughChildren: false }).childIds.size > 0;
|
|
245
|
+
const through = hasChildren ? `<label class="hx-lines-switch"><input type="checkbox" data-corn="lines-switch" data-lines-switch data-focus-key="switch"${state.throughChildren ? ' checked' : ''}> <span>${escHtml(t('throughChildren'))}</span></label>` : '';
|
|
246
|
+
const { connected, off } = reach();
|
|
247
|
+
return `<div class="hx-sec-block hx-lines" id="drawer-lines" data-corn="lines-by-kind"><h3 class="hx-sec-title">Lines</h3><div class="hx-chips" role="group" aria-label="Lit lines by kind">${chips}</div>${list}${through}<div class="hx-lines-reach"><span data-lines-reach>${escHtml(connectedLine(connected, off))}</span> <button type="button" data-corn="frame-button" data-corn-kind="secondary" class="hx-btn hx-btn--secondary" data-action="frame-selection" data-focus-key="frame">${escHtml(t('frame'))}</button></div></div>`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Draws the lines block again after a switch or a kind was chosen; the focus stays on the control that was used */
|
|
251
|
+
function paintLines() {
|
|
252
|
+
const box = $('drawer-lines');
|
|
253
|
+
if (!box || !state.selectedNode) return;
|
|
254
|
+
const key = document.activeElement && box.contains(document.activeElement) ? document.activeElement.dataset.focusKey : '';
|
|
255
|
+
const html = linesHtml(state.selectedNode);
|
|
256
|
+
const holder = document.createElement('div');
|
|
257
|
+
holder.innerHTML = html;
|
|
258
|
+
const next = holder.firstElementChild;
|
|
259
|
+
if (next) box.replaceWith(next); else box.remove();
|
|
260
|
+
if (key) { const again = $('drawer-lines'); const el = again && [...again.querySelectorAll('[data-focus-key]')].find((x) => x.dataset.focusKey === key); if (el) el.focus(); }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** One step through the panel's lines controls: a kind's chip lights that kind alone (the same chip again lights them all), the switch widens the set */
|
|
264
|
+
function onLinesClick(e) {
|
|
265
|
+
const chip = e.target.closest && e.target.closest('[data-lines-kind]');
|
|
266
|
+
if (!chip || !state.selectedNode) return false;
|
|
267
|
+
const kind = chip.dataset.linesKind;
|
|
268
|
+
state.selectedKind = state.selectedKind === kind ? null : kind;
|
|
269
|
+
touchScene();
|
|
270
|
+
render();
|
|
271
|
+
paintLines();
|
|
272
|
+
const sub = litNow();
|
|
273
|
+
announce(sub && sub.kind ? `Showing ${kindPanelWord(sub.kind).toLowerCase()} only: ${sub.edges.length} ${sub.edges.length === 1 ? 'line' : 'lines'}` : 'Showing every kind of line');
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
function onLinesChange(e) {
|
|
277
|
+
const box = e.target.closest && e.target.closest('[data-lines-switch]');
|
|
278
|
+
if (!box || !state.selectedNode) return;
|
|
279
|
+
state.throughChildren = !!box.checked;
|
|
280
|
+
state.selectedKind = null; // the set changed under the chosen kind: it may not be in it
|
|
281
|
+
touchScene();
|
|
282
|
+
render();
|
|
283
|
+
paintLines();
|
|
284
|
+
const sub = litNow();
|
|
285
|
+
announce(`${state.throughChildren ? 'Including' : 'Not including'} its children's lines: ${sub ? sub.connectedNodeIds.size - 1 : 0} connected`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Keeps "9 connected · 3 off screen" true as the camera moves (after every draw, while a node is selected and its panel is open) */
|
|
289
|
+
onPaint(() => {
|
|
290
|
+
if (!state.selectedNode) return;
|
|
291
|
+
const el = document.querySelector('[data-lines-reach]');
|
|
292
|
+
if (!el) return;
|
|
293
|
+
const { connected, off } = reach();
|
|
294
|
+
const text = connectedLine(connected, off);
|
|
295
|
+
if (el.textContent !== text) el.textContent = text;
|
|
296
|
+
});
|
|
297
|
+
|
|
223
298
|
// ---------------------------------------------------------------------------
|
|
224
299
|
// The drawer
|
|
225
300
|
// ---------------------------------------------------------------------------
|
|
226
301
|
let selectToken = 0;
|
|
227
302
|
|
|
228
|
-
/**
|
|
229
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Selects a node: lights what is one edge from it on the map and fills the side panel. `frame` is for a selection that did not come
|
|
305
|
+
* from a click on the map (a search, a list, a link, the keyboard): the camera then flies to the node and what it lights (selection-model.js);
|
|
306
|
+
* a click leaves the camera where it is (spec 0008 D6).
|
|
307
|
+
*/
|
|
308
|
+
export async function selectNode(node, { frame = false } = {}) {
|
|
230
309
|
if (!node) return;
|
|
231
310
|
const token = ++selectToken;
|
|
232
311
|
clearScenario();
|
|
233
312
|
dismissHint(); // a node has been picked: the hint's job is done for this session
|
|
313
|
+
if (!state.selectedNode || state.selectedNode.id !== node.id) state.selectedKind = null; // a kind chosen for one node means nothing for the next
|
|
234
314
|
state.selectedNode = node;
|
|
235
315
|
state.selectedEdge = null;
|
|
236
316
|
touchScene();
|
|
237
317
|
render();
|
|
238
318
|
|
|
239
319
|
const metaList = $('drawer-meta-list');
|
|
240
|
-
if (!metaList.dataset.moreBound) {
|
|
320
|
+
if (!metaList.dataset.moreBound) {
|
|
321
|
+
metaList.dataset.moreBound = '1';
|
|
322
|
+
metaList.addEventListener('click', (e) => { if (!onLinesClick(e)) toggleCapped(e.target); });
|
|
323
|
+
metaList.addEventListener('change', onLinesChange);
|
|
324
|
+
}
|
|
241
325
|
const openBtn = $('drawer-open-btn');
|
|
242
326
|
const title = $('drawer-title');
|
|
243
327
|
|
|
@@ -257,7 +341,7 @@ export async function selectNode(node) {
|
|
|
257
341
|
if (token !== selectToken) return;
|
|
258
342
|
|
|
259
343
|
const facts = `${node.file ? section('File', [code(node.file)]) : ''}${flowSummary(node)}${dataSummary(node)}`;
|
|
260
|
-
metaList.innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
344
|
+
metaList.innerHTML = `${linesHtml(node)}${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
261
345
|
<div id="drawer-live">${liveSection(node)}</div>
|
|
262
346
|
${nodeMockupsHtml(node.id)}
|
|
263
347
|
<div id="drawer-threads">${threadsSection(node)}</div>
|
|
@@ -285,7 +369,8 @@ export async function selectNode(node) {
|
|
|
285
369
|
$('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
|
|
286
370
|
$('drawer-backdrop').hidden = false;
|
|
287
371
|
showSheet('drawer'); // on a phone it takes Work's place (the node sheet and Work take turns), and comes back from away when its node is tapped again
|
|
288
|
-
|
|
372
|
+
if (frame) frameSelection(); // the panel is open now, so what it covers is known
|
|
373
|
+
else keepSelectedInView();
|
|
289
374
|
}
|
|
290
375
|
|
|
291
376
|
/**
|
|
@@ -541,3 +541,27 @@ export function pinLanes(flow, baseFlow) {
|
|
|
541
541
|
flow.top = top;
|
|
542
542
|
return true;
|
|
543
543
|
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* The reviewer's own what-if edits, counted apart from the proposal's (spec 0007 D5): "yours: +1 node, 1 step changed". Never added to the proposal's
|
|
547
|
+
* numbers, so the reviewer can still tell what the agent proposed. Empty for no edits.
|
|
548
|
+
* @param {{ op?: string }[]} edits the applied edits (whatif-model.js)
|
|
549
|
+
* @param {boolean} [hidden] My edits is off: the map does not show them
|
|
550
|
+
* @returns {string}
|
|
551
|
+
*/
|
|
552
|
+
export function yoursText(edits, hidden = false) {
|
|
553
|
+
const list = Array.isArray(edits) ? edits : [];
|
|
554
|
+
if (!list.length) return '';
|
|
555
|
+
const n = (ops) => list.filter((e) => e && ops.includes(e.op)).length;
|
|
556
|
+
const unit = (k, word) => `${k} ${word}${k === 1 ? '' : 's'}`;
|
|
557
|
+
const parts = [];
|
|
558
|
+
if (n(['add-node'])) parts.push(`+${unit(n(['add-node']), 'node')}`);
|
|
559
|
+
if (n(['add-edge'])) parts.push(`+${unit(n(['add-edge']), 'edge')}`);
|
|
560
|
+
if (n(['remove-node'])) parts.push(`\u2212${unit(n(['remove-node']), 'node')}`);
|
|
561
|
+
if (n(['remove-edge'])) parts.push(`\u2212${unit(n(['remove-edge']), 'edge')}`);
|
|
562
|
+
const steps = n(['add-step', 'reword-step', 'delete-step', 'move-step']);
|
|
563
|
+
if (steps) parts.push(`${unit(steps, 'step')} changed`);
|
|
564
|
+
const rest = list.length - n(['add-node', 'add-edge', 'remove-node', 'remove-edge', 'add-step', 'reword-step', 'delete-step', 'move-step']);
|
|
565
|
+
if (rest > 0) parts.push(unit(rest, 'other edit'));
|
|
566
|
+
return `yours: ${parts.join(', ')}${hidden ? ' (hidden)' : ''}`;
|
|
567
|
+
}
|
package/explorer/proposal.js
CHANGED
|
@@ -29,6 +29,7 @@ import { looksWith, onMapStyleChange } from './map-style.js';
|
|
|
29
29
|
import {
|
|
30
30
|
PROPOSAL_VIEWS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds, viewWords, jumpWords,
|
|
31
31
|
sourceChip, pullNumberOf, notFoundWords, otherCopies, malformedLinkWords,
|
|
32
|
+
yoursText,
|
|
32
33
|
} from './proposal-model.js';
|
|
33
34
|
import { renderReviewColumn, reviewOpenedLine, showSection, setPullHead } from './review-column.js';
|
|
34
35
|
import { applyProposal, edgeKey, proposalProblems, summarize } from '../core/proposal.js';
|
|
@@ -122,7 +123,8 @@ export async function openProposal(slug, source = null) {
|
|
|
122
123
|
const found = res.headers.get('X-Proposal-Source');
|
|
123
124
|
let item;
|
|
124
125
|
try { item = await res.json(); } catch { throw new Error(`${slug} could not be opened: cornfield sent a file this page could not read.`); }
|
|
125
|
-
|
|
126
|
+
const sha256 = res.headers.get('X-Proposal-Sha256'); // the version on screen: a review names it, so a push since is refused, not approved unseen
|
|
127
|
+
showProposal(item, { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true, sha256 });
|
|
126
128
|
// said once, here: a proposal opens on a person's asking, never on a background refresh
|
|
127
129
|
announce(reviewOpenedLine($('proposal-title').textContent));
|
|
128
130
|
return true;
|
|
@@ -148,14 +150,16 @@ let openToken = 0;
|
|
|
148
150
|
/**
|
|
149
151
|
* Puts a parsed proposal on the map. The map's nodes and edges become `applyProposal(base, proposal)`.
|
|
150
152
|
* @param {object} proposal
|
|
151
|
-
* @param {{slug?: string|null, source?: string|null, pinSource?: boolean, view?: 'before'|'diff'|'after', fit?: boolean}} [opts]
|
|
153
|
+
* @param {{slug?: string|null, source?: string|null, pinSource?: boolean, view?: 'before'|'diff'|'after', fit?: boolean, sha256?: string|null}} [opts]
|
|
154
|
+
* `sha256`: the file's SHA-256 as the server sent it (X-Proposal-Sha256): a review names it (spec 0007)
|
|
152
155
|
* `fit`: fit the camera to what the proposal touches and what it connects to (default true).
|
|
153
156
|
* `pinSource`: put `&source=` in the address (it was asked for by name; otherwise `/?proposal=<slug>` finds the same one)
|
|
154
157
|
*/
|
|
155
|
-
export function showProposal(proposal, { slug = null, source = null, pinSource = false, view, fit = true } = {}) {
|
|
158
|
+
export function showProposal(proposal, { slug = null, source = null, pinSource = false, view, fit = true, sha256 = null } = {}) {
|
|
156
159
|
state.proposal = proposal;
|
|
157
160
|
state.proposalSlug = slug;
|
|
158
161
|
state.proposalSource = source;
|
|
162
|
+
state.proposalSha256 = typeof sha256 === 'string' && /^[0-9a-f]{64}$/.test(sha256) ? sha256 : null;
|
|
159
163
|
pinnedSource = pinSource;
|
|
160
164
|
if (view) state.proposalView = view;
|
|
161
165
|
else if (!PROPOSAL_VIEWS.includes(state.proposalView)) state.proposalView = 'diff';
|
|
@@ -198,6 +202,7 @@ export function closeProposal() {
|
|
|
198
202
|
state.effectiveProposal = null;
|
|
199
203
|
state.proposalSlug = null;
|
|
200
204
|
state.proposalSource = null;
|
|
205
|
+
state.proposalSha256 = null;
|
|
201
206
|
state.proposalErrors = [];
|
|
202
207
|
swapMap(state.baseNodes.map((n) => ({ ...n })), state.baseEdges);
|
|
203
208
|
fitGraphToViewport(fitPadding());
|
|
@@ -371,6 +376,9 @@ export function renderBar() {
|
|
|
371
376
|
if (!c.mark && /scenarios?$/.test(c.text)) return `<button type="button" class="hx-proposal-count" data-action="review-show-scenarios" data-corn-kind="quiet" title="Show the personas and their scenarios">${escHtml(c.text)}</button>`;
|
|
372
377
|
return `<button type="button" class="hx-proposal-count" data-action="review-show-changes" data-corn-kind="quiet" title="Show the list of changes">${dot}${escHtml(c.text)}</button>`;
|
|
373
378
|
}).join('<span class="hx-proposal-sep" aria-hidden="true"> · </span>');
|
|
379
|
+
// The reviewer's own edits are a part of their own, never added to the proposal's numbers (spec 0007 D5)
|
|
380
|
+
const yours = yoursText(state.whatIf && state.whatIf.edits, !!state.whatIfOff);
|
|
381
|
+
if (yours) chip.insertAdjacentHTML('beforeend', `<span class="hx-proposal-sep" aria-hidden="true"> · </span><span class="hx-proposal-count hx-proposal-yours"><span class="hx-mark-dot hx-mark-dot--edit" data-corn="mark-dot" data-corn-state="edit" aria-hidden="true"></span>${escHtml(yours)}</span>`);
|
|
374
382
|
$('proposal-mode').textContent = t(state.proposalView);
|
|
375
383
|
|
|
376
384
|
for (const btn of bar.querySelectorAll('[data-action="proposal-view"]')) {
|
|
@@ -394,14 +402,13 @@ export function renderBar() {
|
|
|
394
402
|
* Picks a row of the changes list: select it, centre it in the part of the map the review column, the node panel and (on a phone) the sheets leave free,
|
|
395
403
|
* at a zoom where its label reads, and make sure the current view shows it
|
|
396
404
|
*/
|
|
397
|
-
function focusChange(kind, key) {
|
|
405
|
+
export function focusChange(kind, key, { select = true } = {}) {
|
|
398
406
|
const item = kind === 'edge' ? state.edges.find((e) => edgeKey(e) === key) : state.nodes.find((n) => n.id === key);
|
|
399
407
|
if (!item) return;
|
|
400
408
|
const ends = (kind === 'edge' ? [state.nodes.find((n) => n.id === item.from), state.nodes.find((n) => n.id === item.to)] : [item]).filter(Boolean);
|
|
401
409
|
if (!ends.length) return;
|
|
402
410
|
if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff', { quiet: true }); // Before or After hides what it removes or adds
|
|
403
|
-
if (kind === 'edge') showEdgePanel(item);
|
|
404
|
-
else selectNode(item);
|
|
411
|
+
if (select) { if (kind === 'edge') showEdgePanel(item); else selectNode(item); }
|
|
405
412
|
// The panel is open now, so what it covers is known
|
|
406
413
|
const cam = frameNodes(ends, visibleMapRect(), { padding: fitPadding(), maxZoom: Math.max(READ_ZOOM, state.camera.zoom), minZoom: getMinZoom() });
|
|
407
414
|
if (cam) Object.assign(state.camera, cam);
|
package/explorer/render.js
CHANGED
|
@@ -22,8 +22,8 @@ import { ZOOM_MIN, ZOOM_FLOOR } from './camera.js';
|
|
|
22
22
|
// ---------------------------------------------------------------------------
|
|
23
23
|
export const isNodeVisible = (node) => nodeVisible(state, node);
|
|
24
24
|
|
|
25
|
-
/** The focus subgraph: the selected node
|
|
26
|
-
export const getActiveSubgraph = (selected, edges = viewEdges()) => activeSubgraph(selected, edges);
|
|
25
|
+
/** The focus subgraph: the selected node and every node one edge away (selection-model.js); the switch and the kind come from the state */
|
|
26
|
+
export const getActiveSubgraph = (selected, edges = viewEdges(), opts = { throughChildren: !!state.throughChildren, kind: state.selectedKind || null }) => activeSubgraph(selected, edges, opts);
|
|
27
27
|
|
|
28
28
|
// ---------------------------------------------------------------------------
|
|
29
29
|
// Scene and renderer
|