@popcorn245/cornfield 0.49.0 → 0.50.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/explorer/css/review.css +49 -0
- package/explorer/decision-model.js +6 -0
- package/explorer/engine/layout.js +8 -3
- package/explorer/engine/sheets.js +40 -7
- package/explorer/engine/topology.js +126 -0
- package/explorer/instance.js +5 -1
- package/explorer/pieces/changes.js +2 -9
- package/explorer/pieces/decision.js +10 -3
- package/explorer/pieces/map.js +4 -23
- package/explorer/pieces/review.js +280 -0
- package/explorer/view.js +6 -59
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* review.css: the review's own layout
|
|
3
|
+
* What only the one-tag review (explorer/pieces/review.js, `<corn-review>`) needs, and cornfield's page does not load: the box the whole review lives in,
|
|
4
|
+
* and the stage inside it that cornfield's page has in page.css. Every other rule the review reads is the pieces' own file (base, map, node-panel, proposal,
|
|
5
|
+
* changes, decision, sheets: review.js `STYLESHEETS` lists them in order, this one last).
|
|
6
|
+
* No rule here asks what the document says (`:root`, `html`, `body`, `[data-theme]`), sizes from the window (`vw`, `vh`) or is `position: fixed` unless it says why;
|
|
7
|
+
* a width rule is a container query on `corn-box` (the review's box), a height rule on `corn-page`. base.css loads first.
|
|
8
|
+
*/
|
|
9
|
+
/* The box: where the review lives in a host's page. It fills the host (which gives it a height) and is never under 24rem, so a review dropped in with no
|
|
10
|
+
height is visible. It is the query container every piece's width and height rule asks (`corn-box`: its width, `corn-page`: its height), as the body is
|
|
11
|
+
on cornfield's page. `contain: layout` makes it the containing block of its own `position: fixed` descendants (a phone's tap-away behind the node panel,
|
|
12
|
+
the modal scrims) and a stacking context, so nothing in it is placed against the window or above the host's own layers. `all: initial` first: the host's
|
|
13
|
+
font, line height, colour and text settings stop here, as the page's body sets them for the page. */
|
|
14
|
+
[data-corn="review"] {
|
|
15
|
+
all: initial;
|
|
16
|
+
position: relative;
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
width: 100%;
|
|
21
|
+
height: 100%;
|
|
22
|
+
min-height: 24rem;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
container: corn-box corn-page / size;
|
|
25
|
+
contain: layout;
|
|
26
|
+
background-color: var(--corn-ground);
|
|
27
|
+
background-image: var(--corn-ground-image);
|
|
28
|
+
color: var(--corn-text);
|
|
29
|
+
font-family: var(--corn-font);
|
|
30
|
+
-webkit-font-smoothing: antialiased;
|
|
31
|
+
user-select: none;
|
|
32
|
+
}
|
|
33
|
+
/* The stage: the map and what lies over it (page.css has it for the page, with the same rules as media queries: here the box is as wide as the review) */
|
|
34
|
+
.hx-stage { position: relative; flex: 1; width: 100%; min-height: 0; overflow: hidden; }
|
|
35
|
+
/* The scenario player is one bar under the map, to the right of the review column: the stage tells it how wide the column is (page.css, as container queries) */
|
|
36
|
+
@container corn-box (min-width: 768px) {
|
|
37
|
+
.hx-stage:has(.hx-review-column:not([hidden])) { --hx-col-w: 400px; }
|
|
38
|
+
}
|
|
39
|
+
@container corn-box (min-width: 768px) and (max-width: 1023px) {
|
|
40
|
+
.hx-stage:has(.hx-review-column:not([hidden])) { --hx-col-w: 320px; }
|
|
41
|
+
}
|
|
42
|
+
/* A topology with no nodes: the words in the middle of the stage, over the empty map */
|
|
43
|
+
.hx-review-empty { position: absolute; inset: 0; z-index: 1; display: flex; align-items: center; justify-content: center; margin: 0; padding: var(--corn-space-5); text-align: center; color: var(--corn-text-2); font-size: var(--corn-text-md); pointer-events: none; }
|
|
44
|
+
/* No header above the map and no hint on it: the bar sits at the top of the stage */
|
|
45
|
+
.hx-proposal-bar { top: 12px; }
|
|
46
|
+
/* A host's own rules on bare elements reach in (no shadow root: the host's CSS reaches each piece directly, spec 0011 D7); these are the few the pieces never
|
|
47
|
+
set, so they cannot be told apart from the host's: a border drawn round every canvas, an indent on every paragraph */
|
|
48
|
+
[data-corn="review"] canvas { border: 0; }
|
|
49
|
+
[data-corn="review"] :is(p, h1, h2, h3, h4) { text-indent: 0; font-variant: normal; }
|
|
@@ -131,6 +131,12 @@ export function askWords(reasons, verb = 'Approve') {
|
|
|
131
131
|
/** The reasons that ask now and the maintainer has not answered yet (`answered`: the keys confirmed with "Approve anyway"): at the end of the hold, only a new one asks again */
|
|
132
132
|
export const newReasons = (reasons, answered) => reasons.filter((r) => !answered.includes(r.key));
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* What the foot says, in place of Approve and Send back, for a proposal that names nothing to decide on: one a host handed in as an object with no
|
|
136
|
+
* cornfield server to send a review to (pieces/review.js with no `base`). Cornfield's own page always names its proposal, so it never says this.
|
|
137
|
+
*/
|
|
138
|
+
export const NOTHING_TO_DECIDE = 'Shown to read only: there is no cornfield server here to send an approval or a send back to.';
|
|
139
|
+
|
|
134
140
|
/**
|
|
135
141
|
* The line above Approve and what a press of it does, from the facts and the page's own state.
|
|
136
142
|
* @param {object} input
|
|
@@ -59,6 +59,9 @@ export function labelWidth(inst, node) {
|
|
|
59
59
|
const DATA_TYPES = ['store', 'table', 'rom'];
|
|
60
60
|
const CHILD_TYPE_ORDER = ['core', 'atom', 'molecule', 'token', 'page', 'service', 'external', 'stack', 'table', 'store', 'tool', 'app', 'pkg'];
|
|
61
61
|
|
|
62
|
+
/** How deep packTree nests a cluster's own clusters (a real map nests a few levels) */
|
|
63
|
+
const PACK_DEPTH = 64;
|
|
64
|
+
|
|
62
65
|
/** Concentric rings of `items` around (0, 0): returns the offsets and the radii used */
|
|
63
66
|
function ringPack(items, { first = 110, gap = 76, spacing = 90 } = {}) {
|
|
64
67
|
const offsets = [];
|
|
@@ -90,14 +93,16 @@ function ringPack(items, { first = 110, gap = 76, spacing = 90 } = {}) {
|
|
|
90
93
|
* `kidsOf(node)` says who hangs under a node. Returns `{ children, offsets, radii, subs, extent }`: `subs[i]` is the
|
|
91
94
|
* child i's own pack (or null), `extent` how far the whole thing reaches from the centre.
|
|
92
95
|
*/
|
|
93
|
-
function packTree(children, kidsOf, spacingOf, byOrder, seen = new Set()) {
|
|
96
|
+
function packTree(children, kidsOf, spacingOf, byOrder, seen = new Set(), depth = 0) {
|
|
94
97
|
const withSub = [];
|
|
95
98
|
const plain = [];
|
|
96
99
|
children.forEach((c) => {
|
|
97
|
-
|
|
100
|
+
// Deeper than PACK_DEPTH a child is packed as a leaf, and its own children are placed around it after (the last pass of layoutOrbit): a map
|
|
101
|
+
// nested thousands deep is laid out, never a stack overflow
|
|
102
|
+
const kids = seen.has(c.id) || depth >= PACK_DEPTH ? [] : kidsOf(c);
|
|
98
103
|
if (!kids.length) { plain.push(c); return; }
|
|
99
104
|
seen.add(c.id);
|
|
100
|
-
const sub = packTree(kids.sort(byOrder), kidsOf, spacingOf, byOrder, seen);
|
|
105
|
+
const sub = packTree(kids.sort(byOrder), kidsOf, spacingOf, byOrder, seen, depth + 1);
|
|
101
106
|
withSub.push({ c, sub, fp: sub.extent });
|
|
102
107
|
});
|
|
103
108
|
withSub.sort((a, b) => b.fp - a.fp);
|
|
@@ -37,6 +37,7 @@ function sheetsOf(inst) {
|
|
|
37
37
|
away: new Set(), // sheets displaced by the other of their group: open on the page, hidden until opened again
|
|
38
38
|
listeners: new Set(),
|
|
39
39
|
dock: null,
|
|
40
|
+
box: null, // the element whose width says phone, instead of the window's (setPhoneBox)
|
|
40
41
|
lastCovered: 0,
|
|
41
42
|
observers: [],
|
|
42
43
|
wiredDock: null,
|
|
@@ -44,7 +45,42 @@ function sheetsOf(inst) {
|
|
|
44
45
|
}));
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
/** The width of a box below which it is a phone's (the CSS's `@container corn-box (max-width: 767px)`) */
|
|
49
|
+
const PHONE_WIDTH = 768;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the instance is laid out as a phone: the window's width on cornfield's page (PHONE_QUERY), or, where the instance has a box of its own
|
|
53
|
+
* (`setPhoneBox`: the one-tag review in another app's page), that box's width, which is what the stylesheets' container queries ask
|
|
54
|
+
*/
|
|
55
|
+
export const isPhone = (inst) => {
|
|
56
|
+
const { box } = sheetsOf(inst);
|
|
57
|
+
if (box) return box.isConnected && box.clientWidth > 0 && box.clientWidth < PHONE_WIDTH;
|
|
58
|
+
return !!(inst.win && typeof inst.win.matchMedia === 'function' && inst.win.matchMedia(PHONE_QUERY).matches);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Makes `el`'s width, not the window's, say whether the instance is a phone's (the review piece's box in another app's page); null goes back to the window's */
|
|
62
|
+
export function setPhoneBox(inst, el) {
|
|
63
|
+
sheetsOf(inst).box = el || null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Calls `fn` when the instance becomes a phone's or stops being one (the window's width, or the phone box's). Returns how to stop. */
|
|
67
|
+
export function onPhoneChange(inst, fn) {
|
|
68
|
+
const { box } = sheetsOf(inst);
|
|
69
|
+
const RO = inst.win && inst.win.ResizeObserver;
|
|
70
|
+
if (box && typeof RO === 'function') {
|
|
71
|
+
let was = isPhone(inst);
|
|
72
|
+
const ro = new RO(() => { const now = isPhone(inst); if (now !== was) { was = now; fn(); } });
|
|
73
|
+
ro.observe(box);
|
|
74
|
+
const off = () => { ro.disconnect(); inst.release(off); };
|
|
75
|
+
inst.own(off);
|
|
76
|
+
return off;
|
|
77
|
+
}
|
|
78
|
+
if (inst.win && typeof inst.win.matchMedia === 'function') {
|
|
79
|
+
const mq = inst.win.matchMedia(PHONE_QUERY);
|
|
80
|
+
if (mq && mq.addEventListener) return inst.listen(mq, 'change', () => fn());
|
|
81
|
+
}
|
|
82
|
+
return () => {};
|
|
83
|
+
};
|
|
48
84
|
|
|
49
85
|
const stageOf = (inst, S) => (S.dock && S.dock.parentElement) || (inst.state.canvas ? inst.state.canvas.parentElement : null);
|
|
50
86
|
|
|
@@ -78,8 +114,8 @@ function apply(inst) {
|
|
|
78
114
|
}
|
|
79
115
|
const stage = stageOf(inst, S);
|
|
80
116
|
if (stage) stage.dataset.sheetOpen = model.expanded() || '';
|
|
81
|
-
// The expanded sheet is capped so the map keeps 35% of the screen: what is left under the stub, if there is one
|
|
82
|
-
if (S.dock && isPhone(inst)) S.dock.style.setProperty('--hx-sheet-cap', `${sheetCap(inst.win.innerHeight || 0, model.stubs())}px`);
|
|
117
|
+
// The expanded sheet is capped so the map keeps 35% of the screen (of the box, where the instance has one): what is left under the stub, if there is one
|
|
118
|
+
if (S.dock && isPhone(inst)) S.dock.style.setProperty('--hx-sheet-cap', `${sheetCap((S.box ? S.box.clientHeight : inst.win.innerHeight) || 0, model.stubs())}px`);
|
|
83
119
|
markLast(inst);
|
|
84
120
|
measureCovered(inst);
|
|
85
121
|
S.listeners.forEach((fn) => fn());
|
|
@@ -408,10 +444,7 @@ export function initSheets(inst) {
|
|
|
408
444
|
S.documentWired = true;
|
|
409
445
|
for (const type of ['pointerdown', 'touchstart', 'mousedown']) inst.listen(inst.root, type, (e) => onMapDown(inst, e), { passive: true, capture: true });
|
|
410
446
|
inst.listen(inst.root, 'keydown', (e) => onEscape(inst, e), true);
|
|
411
|
-
|
|
412
|
-
const mq = inst.win.matchMedia(PHONE_QUERY);
|
|
413
|
-
if (mq && mq.addEventListener) inst.listen(mq, 'change', () => { collapseAllSheets(inst); measureCovered(inst); });
|
|
414
|
-
}
|
|
447
|
+
onPhoneChange(inst, () => { collapseAllSheets(inst); measureCovered(inst); });
|
|
415
448
|
}
|
|
416
449
|
apply(inst);
|
|
417
450
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/engine/topology
|
|
3
|
+
*
|
|
4
|
+
* Giving an instance its map (spec 0011 D2, D4: the engine half of the one-tag review). A host hands a topology in (`{ nodes, edges }`, the object
|
|
5
|
+
* topology.json holds); this is the one place it becomes the instance's state, for the map piece (pieces/map.js) and for the review piece
|
|
6
|
+
* (pieces/review.js), which both call it. Nothing here reads the address or fetches: a piece that loads a topology from a server hands the object over.
|
|
7
|
+
*
|
|
8
|
+
* setTopology(inst, topology) copies the nodes and edges in as the base map (the host's object is never changed: the layout writes on the copies),
|
|
9
|
+
* builds the data-flow preset, keeps the selection when its node is still there; returns whether it is
|
|
10
|
+
* layoutMap(inst, { placeLive }) where the nodes sit for the current view (orbit, or the data-flow lanes). With a proposal open (or live nodes
|
|
11
|
+
* laid in) the base is laid out on its own and the nodes that were there keep their places; only what a proposal adds
|
|
12
|
+
* is placed beside it (proposal-model.js), and the live layer by `placeLive` (cornfield's page hands live-model.js's,
|
|
13
|
+
* which no component carries). The ONE layout: cornfield's page (view.js), the map piece and the review piece all
|
|
14
|
+
* call it. The camera is the caller's
|
|
15
|
+
* setMap(inst, nodes, edges) the map the instance draws from `nodes` and `edges` (the base, or `applyProposal(base, proposal)` while a proposal is
|
|
16
|
+
* open), laid out by layoutMap. It is what the instance answers to the `map:set` ask of engine/proposal.js (the review
|
|
17
|
+
* piece answers it; cornfield's page answers with view.js, which lays in its live layer first and then calls layoutMap)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { buildDataFlow } from '../flow-build.js';
|
|
21
|
+
import { orderAddedLast, pinLanes, placeAddedNodes } from '../proposal-model.js';
|
|
22
|
+
import { computeDegreeCentrality, computeLaneLayout, layoutOrbit } from './layout.js';
|
|
23
|
+
|
|
24
|
+
/** The nodes and edges of a topology that have what the engine needs (an id, and two ends), as arrays; anything else is dropped */
|
|
25
|
+
export function cleanTopology(topology) {
|
|
26
|
+
const nodes = topology && Array.isArray(topology.nodes) ? topology.nodes.filter((n) => n && typeof n.id === 'string') : [];
|
|
27
|
+
const edges = topology && Array.isArray(topology.edges) ? topology.edges.filter((e) => e && typeof e.from === 'string' && typeof e.to === 'string') : [];
|
|
28
|
+
return { nodes, edges };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Makes `topology` the instance's base map. The selection outlives it when the new map has its node (the same id is the same selection, the
|
|
33
|
+
* instance says nothing), else it is cleared (the instance says so once). The scene is touched; laying out and drawing are the caller's.
|
|
34
|
+
* @param {ReturnType<import('../instance.js').createInstance>} inst
|
|
35
|
+
* @param {{ nodes?: object[], edges?: object[] } | null | undefined} topology
|
|
36
|
+
* @returns {boolean} whether the map has any nodes
|
|
37
|
+
*/
|
|
38
|
+
export function setTopology(inst, topology) {
|
|
39
|
+
const { state } = inst;
|
|
40
|
+
const { nodes, edges } = cleanTopology(topology);
|
|
41
|
+
const keep = state.selectedNode ? state.selectedNode.id : null;
|
|
42
|
+
// The host's object is never changed: the map works on copies (the layout writes positions on them)
|
|
43
|
+
state.baseNodes = nodes;
|
|
44
|
+
state.baseEdges = edges;
|
|
45
|
+
state.nodes = nodes.map((n) => ({ ...n }));
|
|
46
|
+
state.edges = edges.map((e) => ({ ...e }));
|
|
47
|
+
state.mapNodes = state.nodes;
|
|
48
|
+
state.mapEdges = state.edges;
|
|
49
|
+
state.flow = buildDataFlow(state.nodes, state.edges);
|
|
50
|
+
const again = keep ? state.nodes.find((n) => n.id === keep) || null : null;
|
|
51
|
+
if (again) { state.selectedEdge = null; state.selectedNode = again; } else if (state.selectedNode || state.selectedEdge) { state.selectedNode = null; state.selectedEdge = null; }
|
|
52
|
+
inst.touchScene();
|
|
53
|
+
return state.nodes.length > 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Where nodes sit for the current view: sizes by degree, then the data-flow lanes or the orbit. With a proposal open the base map is laid out on its
|
|
58
|
+
* own, exactly as it is with none, and the nodes that were there keep those places and sizes: opening a proposal, switching Before, Diff and After,
|
|
59
|
+
* and closing it never move a node that was already on the map; an added node takes a free cell in its lane, or a place beside its parent. Live
|
|
60
|
+
* nodes (cornfield's page lays its live layer in: view.js) are placed beside the code map the same way.
|
|
61
|
+
*/
|
|
62
|
+
export function layoutMap(inst, { placeLive } = {}) {
|
|
63
|
+
const { state } = inst;
|
|
64
|
+
computeDegreeCentrality(inst); // node sizes: by degree on the full map ...
|
|
65
|
+
if (state.view === 'dataflow' && state.flow) {
|
|
66
|
+
state.flow.tiers.forEach((tier) => tier.nodes.forEach((n) => { n.r = Math.min(n.r, 13); })); // ... all small in the lanes
|
|
67
|
+
if (!(state.proposal && state.baseNodes && lanesAround(inst))) computeLaneLayout(inst, state.flow);
|
|
68
|
+
} else if (state.baseNodes && (state.proposal || state.nodes.some((n) => n.live))) {
|
|
69
|
+
orbitAround(inst, placeLive); // the code map keeps its places; what a proposal adds and the live layer are placed beside it
|
|
70
|
+
} else layoutOrbit(inst);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Puts `nodes` and `edges` on the map and lays them out (layoutMap): the data-flow preset is rebuilt from them, an added node last in its lane.
|
|
75
|
+
*/
|
|
76
|
+
export function setMap(inst, nodes, edges) {
|
|
77
|
+
const { state } = inst;
|
|
78
|
+
state.mapNodes = nodes;
|
|
79
|
+
state.mapEdges = edges;
|
|
80
|
+
state.nodes = nodes;
|
|
81
|
+
state.edges = edges;
|
|
82
|
+
state.flow = buildDataFlow(nodes, edges);
|
|
83
|
+
orderAddedLast(state.flow); // an added node goes last in its lane, so the nodes that were there keep their rows
|
|
84
|
+
inst.touchScene();
|
|
85
|
+
layoutMap(inst);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The data-flow lanes while a proposal is open: the base is laid out on its own and pinned, the added nodes take free cells; false when that cannot be done */
|
|
89
|
+
function lanesAround(inst) {
|
|
90
|
+
const { state } = inst;
|
|
91
|
+
const applied = { nodes: state.nodes, edges: state.edges };
|
|
92
|
+
const laid = state.baseNodes.map((n) => ({ ...n }));
|
|
93
|
+
state.nodes = laid;
|
|
94
|
+
state.edges = state.baseEdges;
|
|
95
|
+
computeDegreeCentrality(inst);
|
|
96
|
+
const baseFlow = buildDataFlow(laid, state.baseEdges);
|
|
97
|
+
baseFlow.tiers.forEach((tier) => tier.nodes.forEach((n) => { n.r = Math.min(n.r, 13); }));
|
|
98
|
+
computeLaneLayout(inst, baseFlow);
|
|
99
|
+
state.nodes = applied.nodes;
|
|
100
|
+
state.edges = applied.edges;
|
|
101
|
+
const pinned = pinLanes(state.flow, baseFlow);
|
|
102
|
+
inst.touchScene();
|
|
103
|
+
return pinned;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The orbit while a proposal is open (or live nodes are in): the base is laid out as it is with none, and only the added nodes are placed, next to their parent */
|
|
107
|
+
function orbitAround(inst, placeLive) {
|
|
108
|
+
const { state } = inst;
|
|
109
|
+
const applied = { nodes: state.nodes, edges: state.edges };
|
|
110
|
+
const laid = state.baseNodes.map((n) => ({ ...n }));
|
|
111
|
+
state.nodes = laid;
|
|
112
|
+
state.edges = state.baseEdges;
|
|
113
|
+
computeDegreeCentrality(inst);
|
|
114
|
+
layoutOrbit(inst); // also sets the rings
|
|
115
|
+
const at = new Map(laid.map((n) => [n.id, n]));
|
|
116
|
+
state.nodes = applied.nodes;
|
|
117
|
+
state.edges = applied.edges;
|
|
118
|
+
computeDegreeCentrality(inst);
|
|
119
|
+
state.nodes.forEach((n) => {
|
|
120
|
+
const was = at.get(n.id);
|
|
121
|
+
if (was) { n.x = was.x; n.y = was.y; n.r = was.r; }
|
|
122
|
+
});
|
|
123
|
+
placeAddedNodes(state.nodes, state.edges);
|
|
124
|
+
if (placeLive) placeLive(state.nodes, state.edges);
|
|
125
|
+
inst.touchScene();
|
|
126
|
+
}
|
package/explorer/instance.js
CHANGED
|
@@ -248,7 +248,11 @@ export function createInstance({ root: rootOpt = null, base = '', fetch: fetchOp
|
|
|
248
248
|
active: () => {
|
|
249
249
|
if (!root || !doc) return null;
|
|
250
250
|
if (root.nodeType !== 1) return root.activeElement || null; // a Document or a shadow root
|
|
251
|
-
|
|
251
|
+
// An element: the focus is asked of the tree it sits in, so an element inside a shadow root (the review piece's box in a shell's shadow root)
|
|
252
|
+
// finds its own focused element, where the document's would be the shadow root's host
|
|
253
|
+
const tree = typeof root.getRootNode === 'function' ? root.getRootNode() : doc;
|
|
254
|
+
const focused = tree && tree.activeElement !== undefined ? tree.activeElement : doc.activeElement;
|
|
255
|
+
return focused && root.contains(focused) ? focused : null;
|
|
252
256
|
},
|
|
253
257
|
|
|
254
258
|
// -- what the viewer prefers --------------------------------------------------------------------------------------------------
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
39
39
|
import { t } from '../engine/strings.js';
|
|
40
40
|
import { markStateAttr } from '../corn-state.js';
|
|
41
|
-
import { isPhone, expandSheet,
|
|
41
|
+
import { isPhone, expandSheet, onPhoneChange, visibleMapRect } from '../engine/sheets.js';
|
|
42
42
|
import { pullNumberOf } from '../proposal-model.js';
|
|
43
43
|
import { clearSelection } from '../engine/selection.js';
|
|
44
44
|
import { onLayersChange } from '../engine/layers.js';
|
|
@@ -453,14 +453,7 @@ export function mount(root, inst, options = {}) {
|
|
|
453
453
|
const watch = (el, fn) => { if (el && typeof RO === 'function') { const ro = new RO(fn); ro.observe(el); scope.own(() => ro.disconnect()); } };
|
|
454
454
|
watch(inst.el('proposal-bar'), () => placeColumn());
|
|
455
455
|
watch(col, () => shareRoom()); // the window's height changed
|
|
456
|
-
if (
|
|
457
|
-
const mq = inst.win.matchMedia(PHONE_QUERY);
|
|
458
|
-
if (mq && mq.addEventListener) {
|
|
459
|
-
const onPhone = () => { if (state.proposal) renderColumn(); };
|
|
460
|
-
mq.addEventListener('change', onPhone);
|
|
461
|
-
scope.own(() => mq.removeEventListener('change', onPhone));
|
|
462
|
-
}
|
|
463
|
-
}
|
|
456
|
+
scope.own(onPhoneChange(inst, () => { if (state.proposal) renderColumn(); })); // the window's width, or the box's where the review has one (engine/sheets.js)
|
|
464
457
|
|
|
465
458
|
scope.own(() => {
|
|
466
459
|
gone = true;
|
|
@@ -101,11 +101,14 @@ export function mount(root, inst, options = {}) {
|
|
|
101
101
|
const { state } = inst;
|
|
102
102
|
const scope = scopeOf(inst);
|
|
103
103
|
const now = typeof options.now === 'function' ? options.now : () => Date.now();
|
|
104
|
+
/** What the foot says in place of its buttons for a proposal with no name, which nothing can be decided on (the review piece's, with no server); none: the page's */
|
|
105
|
+
const unnamed = typeof options.unnamed === 'string' && options.unnamed ? options.unnamed : '';
|
|
104
106
|
const get = credentialed(inst);
|
|
105
107
|
const made = place(inst, root, markup().foot, options.slots, 'foot');
|
|
106
108
|
scope.keepParts(...made);
|
|
107
109
|
const foot = made[0];
|
|
108
110
|
const rootEl = foot.querySelector('#review');
|
|
111
|
+
const actions = foot.querySelector('.hx-proposal-actions');
|
|
109
112
|
let gone = false;
|
|
110
113
|
|
|
111
114
|
/** What is shown: the review of the proposal that is open, and the lines under the buttons */
|
|
@@ -182,8 +185,12 @@ export function mount(root, inst, options = {}) {
|
|
|
182
185
|
|
|
183
186
|
// The line is Approve's description (the question while one is asked); not on a PR it is the reason for both buttons
|
|
184
187
|
const line = q('[data-review-line]');
|
|
185
|
-
|
|
186
|
-
line
|
|
188
|
+
// A proposal open with no name has nothing to decide on. Where the host says so (`unnamed`: the review piece handed an object with no server),
|
|
189
|
+
// the line says it and there are no buttons to press; cornfield's page (a proposal from the hub) hides the foot's lines as before
|
|
190
|
+
const readOnly = !ui.key && !!state.proposal && !!unnamed;
|
|
191
|
+
line.textContent = ui.key ? d.line : readOnly ? unnamed : '';
|
|
192
|
+
line.hidden = (!ui.key && !readOnly) || !!askText; // the question takes the line's place while one is asked
|
|
193
|
+
actions.hidden = readOnly;
|
|
187
194
|
const ask = q('[data-review-ask]');
|
|
188
195
|
if (ask.textContent !== askText) ask.textContent = askText;
|
|
189
196
|
ask.hidden = !askText;
|
|
@@ -275,7 +282,7 @@ export function mount(root, inst, options = {}) {
|
|
|
275
282
|
/** The bar was drawn: when it is another proposal than the one shown, start again for it */
|
|
276
283
|
function onBar({ open }) {
|
|
277
284
|
const key = open ? keyOf() : null;
|
|
278
|
-
rootEl.hidden = !key;
|
|
285
|
+
rootEl.hidden = !(key || (open && unnamed));
|
|
279
286
|
if (key === ui.key) { paint(); return; }
|
|
280
287
|
if (ui.hold) stopHold(open ? 'other' : 'closed', { quiet: false });
|
|
281
288
|
ui.key = key;
|
package/explorer/pieces/map.js
CHANGED
|
@@ -45,14 +45,13 @@
|
|
|
45
45
|
import { createInstance } from '../instance.js';
|
|
46
46
|
import { createMap } from '../engine/render.js';
|
|
47
47
|
import { mapStyleOf } from '../engine/map-style.js';
|
|
48
|
-
import {
|
|
48
|
+
import { layoutMap, setTopology as installTopology } from '../engine/topology.js';
|
|
49
49
|
import { initKeyboard, resetKeyboard } from '../engine/keyboard.js';
|
|
50
50
|
import { selectNode, clearSelection } from '../engine/selection.js';
|
|
51
51
|
import { stopFlight } from '../engine/fly.js';
|
|
52
52
|
import { scopeOf, place } from '../engine/piece.js';
|
|
53
53
|
import { createRenderer } from '../renderer.js';
|
|
54
54
|
import { bindCanvasInput } from '../input.js';
|
|
55
|
-
import { buildDataFlow } from '../flow-build.js';
|
|
56
55
|
import { resolveTheme } from '../theme-model.js';
|
|
57
56
|
import { escapeHtml } from '../../core/text.js';
|
|
58
57
|
import { adoptDefaultTokens } from './adopt-tokens.js';
|
|
@@ -247,14 +246,8 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
247
246
|
// -- the renderer, the layout --------------------------------------------------------------------------------------------------------
|
|
248
247
|
installRenderer();
|
|
249
248
|
|
|
250
|
-
/** Where nodes sit for the current view */
|
|
251
|
-
|
|
252
|
-
computeDegreeCentrality(inst);
|
|
253
|
-
if (state.view === 'dataflow' && state.flow) {
|
|
254
|
-
state.flow.tiers.forEach((tier) => tier.nodes.forEach((n) => { n.r = Math.min(n.r, 13); })); // all small in the lanes
|
|
255
|
-
computeLaneLayout(inst, state.flow);
|
|
256
|
-
} else layoutOrbit(inst);
|
|
257
|
-
}
|
|
249
|
+
/** Where nodes sit for the current view (engine/topology.js) */
|
|
250
|
+
const applyLayout = () => layoutMap(inst);
|
|
258
251
|
|
|
259
252
|
/** A fit asked for while the map has no box (a parent `display: none`, a box of no size) waits for one: fitted to nothing, the camera would be lost */
|
|
260
253
|
let fitWhenSized = false;
|
|
@@ -329,21 +322,9 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
329
322
|
|
|
330
323
|
// -- changes ---------------------------------------------------------------------------------------------------------------------------------
|
|
331
324
|
function setTopology(topology) {
|
|
332
|
-
const nodes = topology && Array.isArray(topology.nodes) ? topology.nodes.filter((n) => n && typeof n.id === 'string') : [];
|
|
333
|
-
const edges = topology && Array.isArray(topology.edges) ? topology.edges.filter((e) => e && typeof e.from === 'string' && typeof e.to === 'string') : [];
|
|
334
325
|
const keep = state.selectedNode ? state.selectedNode.id : null; // the selection outlives a new topology that has its node
|
|
335
|
-
|
|
336
|
-
state.baseNodes = nodes;
|
|
337
|
-
state.baseEdges = edges;
|
|
338
|
-
state.nodes = nodes.map((n) => ({ ...n }));
|
|
339
|
-
state.edges = edges.map((e) => ({ ...e }));
|
|
340
|
-
state.mapNodes = state.nodes;
|
|
341
|
-
state.mapEdges = state.edges;
|
|
342
|
-
state.flow = buildDataFlow(state.nodes, state.edges);
|
|
326
|
+
installTopology(inst, topology); // the base map, the data-flow preset and the selection kept or cleared (engine/topology.js)
|
|
343
327
|
const again = keep ? nodeById(keep) : null;
|
|
344
|
-
// The same id is the same selection (the instance says nothing); none is a change it says once
|
|
345
|
-
if (again) { state.selectedEdge = null; state.selectedNode = again; } else if (state.selectedNode || state.selectedEdge) { state.selectedNode = null; state.selectedEdge = null; }
|
|
346
|
-
inst.touchScene();
|
|
347
328
|
if (state.nodes.length) { applyLayout(); fit(); }
|
|
348
329
|
const asked = !again && pendingNode ? nodeById(pendingNode) : null; // the node the host asked for before the map had it
|
|
349
330
|
if (asked) selectNode(inst, asked, { source: 'api' });
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/review
|
|
3
|
+
*
|
|
4
|
+
* The review as one piece (spec 0011 D3, D4, D8): the engine half of the coming `<corn-review>`. It lays out, in ONE root and on ONE instance, what a
|
|
5
|
+
* review needs, and mounts the pieces of the explorer into it through their own `mount(root, inst, { slots })`: the map (pieces/map.js), the proposal's
|
|
6
|
+
* bar (pieces/proposal.js, without the what-if editor's buttons: the editor is not converted), the change list with the scenario player
|
|
7
|
+
* (pieces/changes.js), the decision's foot (pieces/decision.js, in the column's foot) and the node panel (pieces/node-panel.js). It is not cornfield's
|
|
8
|
+
* page: no header, Work panel, search, Layers chip, account menu or hint, and cornfield's page does not use it (it keeps its own layout).
|
|
9
|
+
*
|
|
10
|
+
* const review = mount(root, inst, options) -> { update, destroy, ... }
|
|
11
|
+
*
|
|
12
|
+
* root the host's element (or shadow root): the piece makes ONE box in it (`[data-corn="review"]`), and everything it makes is inside that box
|
|
13
|
+
* inst the instance; null makes one over the box, which `destroy()` then ends too. One instance for every piece inside: the lookups by id that
|
|
14
|
+
* still cross pieces (the dock, the bar, the review column, the node panel, the player's place) find their elements because there is one root
|
|
15
|
+
*
|
|
16
|
+
* Options, all optional; `update(next)` takes the same keys and applies what is present:
|
|
17
|
+
* topology {nodes, edges}: the map. The piece does not load it: it takes what it is given (engine/topology.js `setTopology`, which the map piece calls too)
|
|
18
|
+
* proposal a slug (fetched through `inst.fetch`, so a `base` applies; `source` names the copy), or the proposal object (nothing is fetched: `slug`,
|
|
19
|
+
* `source` and `sha256` may name it, which a decision needs; with no `base` and no `fetch` they are ignored, so nothing is sent anywhere), or null: closes it. Held until a topology is there
|
|
20
|
+
* source where the server found the proposal ('checkout', 'pull/24', a worktree)
|
|
21
|
+
* view 'before' | 'diff' | 'after': the proposal's view; or 'map' | 'dataflow': the map's. The two sets of words do not meet
|
|
22
|
+
* node the selected node's id (null clears it)
|
|
23
|
+
* config { theme, layers }: the repo's client config as /cornfield/config.json carries it, which this piece takes and does not fetch: `theme` starts the
|
|
24
|
+
* theme's map icons (they are fetched without the session, with CORS), `layers` are the project's layers
|
|
25
|
+
* strings the host's own words (core/strings.js keys): the instance speaks in them
|
|
26
|
+
* theme 'light' | 'dark' | 'auto' (the map's ground), checker (a plugin's checker for the scenarios), now (the decision's clock)
|
|
27
|
+
* base, fetch, tokens, renderer, onSelect, onReady as pieces/map.js; `renderer` is read at mount only (a canvas that is replaced loses the edge picking)
|
|
28
|
+
* label the box's accessible name (a region; 'Proposal review' by default), read at mount
|
|
29
|
+
*
|
|
30
|
+
* What a host hears is on the instance already (instance.js): `selection`, `proposal`, `decision`, `auth`, `scenario:player`. This piece adds nothing.
|
|
31
|
+
*
|
|
32
|
+
* Where it lives. The box declares itself the query container its stylesheets ask (`container: corn-box corn-page / size`, css/review.css) and is the
|
|
33
|
+
* containing block of its own `position: fixed` descendants (`contain: layout`), so it needs a host that gives it a height (it fills 100% of it and is never
|
|
34
|
+
* under 24rem). Under 768px by the box's own width, not the window's, it is the page's phone layout with its sheets (engine/sheets.js `setPhoneBox`).
|
|
35
|
+
* The stylesheets to load, in order, after the default tokens and before a theme: `STYLESHEETS` below (explorer/css/).
|
|
36
|
+
*
|
|
37
|
+
* Nothing leaves the box: no listener on `document` or `window`, nothing appended outside it, no id looked up outside it, keys act only with the focus
|
|
38
|
+
* inside, no `location`, no `history`; the wheel is the page's until the map has the focus or Ctrl or Cmd is held (input.js).
|
|
39
|
+
*
|
|
40
|
+
* Not in it: the what-if editor, the mockups, the Work panel, search, the Layers menu, the Proposals menu (its markup is kept in a spare, hidden place: the
|
|
41
|
+
* proposal piece makes it), signing in (the decision says `auth`).
|
|
42
|
+
*
|
|
43
|
+
* @param {Element|ShadowRoot} root
|
|
44
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>|null} inst
|
|
45
|
+
* @param {object} [options]
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
import { createInstance } from '../instance.js';
|
|
49
|
+
import { mount as mountMap } from './map.js';
|
|
50
|
+
import { mount as mountNodePanel } from './node-panel.js';
|
|
51
|
+
import { mount as mountProposal } from './proposal.js';
|
|
52
|
+
import { mount as mountChanges } from './changes.js';
|
|
53
|
+
import { mount as mountDecision } from './decision.js';
|
|
54
|
+
import { setTopology, layoutMap, setMap } from '../engine/topology.js';
|
|
55
|
+
import { closeProposal, rebuildProposalMap } from '../engine/proposal.js';
|
|
56
|
+
import { measureCovered, setPhoneBox } from '../engine/sheets.js';
|
|
57
|
+
import { setProjectLayers } from '../engine/layers.js';
|
|
58
|
+
import { applyStrings, setStrings } from '../engine/strings.js';
|
|
59
|
+
import { withParts } from '../engine/piece.js';
|
|
60
|
+
import { PROPOSAL_VIEWS } from '../proposal-model.js';
|
|
61
|
+
import { NOTHING_TO_DECIDE } from '../decision-model.js';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The files of explorer/css/ the review needs, in the order to load them (the cascade's): after the default tokens (explorer/tokens.css, or the
|
|
65
|
+
* generated sheet `tokens` hands the map) and before a theme. Never page.css, which is cornfield's own page. The shell reads this list.
|
|
66
|
+
*/
|
|
67
|
+
export const STYLESHEETS = ['base.css', 'map.css', 'node-panel.css', 'proposal.css', 'changes.css', 'decision.css', 'sheets.css', 'review.css'];
|
|
68
|
+
|
|
69
|
+
/** The keys of the map in the review: the page's, without Freeform (the review has none) */
|
|
70
|
+
export const KEYS_HELP = "Arrow keys pan, plus and minus zoom, 0 fits the map. N and P select the next and the previous node, Home and End the first and the last. F frames the selected node and what it lights. Enter goes to the selected node's panel, Escape closes it.";
|
|
71
|
+
|
|
72
|
+
const MAP_VIEWS = ['map', 'orbit', 'dataflow'];
|
|
73
|
+
|
|
74
|
+
/** What the box says over a map with no nodes */
|
|
75
|
+
export const EMPTY_WORDS = 'There is no map to show: the topology has no nodes.';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The layout: a stage (the map, and over it the dock, which holds the bar, the review column and the node panel, and the tap-away behind the panel on a
|
|
79
|
+
* phone), as cornfield's page has, with each piece's place marked by a comment where its elements go before. The Proposals menu has a spare place of its own.
|
|
80
|
+
*/
|
|
81
|
+
const LAYOUT = '<div class="hx-stage" data-corn="stage">'
|
|
82
|
+
+ '<!--corn-piece:map/stage-->'
|
|
83
|
+
+ '<div id="sheet-dock" class="hx-dock" data-corn="dock">'
|
|
84
|
+
+ '<!--corn-piece:proposal/bar-->'
|
|
85
|
+
+ '<!--corn-piece:changes/column-->'
|
|
86
|
+
+ '<!--corn-piece:node-panel/drawer-->'
|
|
87
|
+
+ '</div>'
|
|
88
|
+
+ '<!--corn-piece:node-panel/backdrop-->'
|
|
89
|
+
+ '<p class="hx-review-empty" data-corn="empty" role="status" hidden></p>'
|
|
90
|
+
+ '</div>'
|
|
91
|
+
+ '<div class="hx-review-spare" hidden><!--corn-piece:proposal/menu--></div>';
|
|
92
|
+
|
|
93
|
+
/** The marker comments under `el`, by `name/slot` */
|
|
94
|
+
function markersIn(doc, el) {
|
|
95
|
+
const found = {};
|
|
96
|
+
const walker = doc.createTreeWalker(el, 128 /* NodeFilter.SHOW_COMMENT */);
|
|
97
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
98
|
+
if (node.data.startsWith('corn-piece:')) found[node.data.slice('corn-piece:'.length)] = node;
|
|
99
|
+
}
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function mount(root, inst, options = {}) {
|
|
104
|
+
const doc = root.ownerDocument || root;
|
|
105
|
+
// -- the box: ONE root for everything the review makes ---------------------------------------------------------------------------------
|
|
106
|
+
const box = doc.createElement('div');
|
|
107
|
+
box.setAttribute('data-corn', 'review');
|
|
108
|
+
box.setAttribute('part', 'review');
|
|
109
|
+
// A named region: a screen reader finds the review as one place in the host's page (its headings start at h2: the proposal's title and the node's)
|
|
110
|
+
box.setAttribute('role', 'region');
|
|
111
|
+
box.setAttribute('aria-label', typeof options.label === 'string' && options.label.trim() ? options.label.trim() : 'Proposal review');
|
|
112
|
+
box.innerHTML = withParts(LAYOUT);
|
|
113
|
+
root.append(box);
|
|
114
|
+
|
|
115
|
+
const ownsInstance = !inst;
|
|
116
|
+
if (ownsInstance) inst = createInstance({ root: box, base: options.base || '', fetch: options.fetch, strings: options.strings });
|
|
117
|
+
else if (options.strings !== undefined) setStrings(inst, options.strings);
|
|
118
|
+
const { state } = inst;
|
|
119
|
+
setPhoneBox(inst, box); // a phone is a narrow box, whatever the window is (engine/sheets.js)
|
|
120
|
+
applyStrings(inst, box);
|
|
121
|
+
let ended = false;
|
|
122
|
+
|
|
123
|
+
// -- the pieces, in the order the page mounts them: the map first, the node panel, the bar, the column, the decision in the column's foot -----
|
|
124
|
+
const at = markersIn(doc, box);
|
|
125
|
+
const mapPiece = mountMap(box, inst, {
|
|
126
|
+
slots: { stage: at['map/stage'] },
|
|
127
|
+
measureCovered: () => measureCovered(inst),
|
|
128
|
+
keysHelp: KEYS_HELP,
|
|
129
|
+
renderer: options.renderer,
|
|
130
|
+
theme: options.theme,
|
|
131
|
+
tokens: options.tokens,
|
|
132
|
+
onSelect: options.onSelect,
|
|
133
|
+
onReady: options.onReady,
|
|
134
|
+
});
|
|
135
|
+
const nodePanel = mountNodePanel(box, inst, { slots: { drawer: at['node-panel/drawer'], backdrop: at['node-panel/backdrop'] } });
|
|
136
|
+
const proposalPiece = mountProposal(box, inst, { slots: { bar: at['proposal/bar'], menu: at['proposal/menu'] }, edit: false });
|
|
137
|
+
const changesPiece = mountChanges(box, inst, { slots: { column: at['changes/column'] }, checker: options.checker });
|
|
138
|
+
const foot = markersIn(doc, box)['decision/foot']; // the column keeps a place for it
|
|
139
|
+
const decisionPiece = mountDecision(box, inst, { slots: { foot }, now: options.now, unnamed: NOTHING_TO_DECIDE }); // handed an object with no server, it says so
|
|
140
|
+
|
|
141
|
+
// The review lays the map out from what the engine hands over (a proposal's nodes and edges are the base with marks): nodes that were there keep their place
|
|
142
|
+
const stopAsking = inst.on('map:set', ({ nodes, edges }) => { setMap(inst, nodes, edges); return true; });
|
|
143
|
+
|
|
144
|
+
// -- what the host asked for ---------------------------------------------------------------------------------------------------------------
|
|
145
|
+
/** What has been handed in, so an `update` that repeats a value changes nothing */
|
|
146
|
+
const serverless = !options.base && !options.fetch;
|
|
147
|
+
const current = { topology: undefined, proposal: null, source: null, slug: null, sha256: null, proposalView: null, shown: null, hasTopology: false, held: false };
|
|
148
|
+
|
|
149
|
+
const redraw = () => { proposalPiece.update(); changesPiece.update(); decisionPiece.update(); nodePanel.update(); };
|
|
150
|
+
|
|
151
|
+
/** The proposal asked for, opened (or closed) once there is a map to open it on */
|
|
152
|
+
function applyProposal() {
|
|
153
|
+
if (ended) return undefined;
|
|
154
|
+
const wanted = current.proposal;
|
|
155
|
+
if (wanted === null || wanted === undefined || wanted === '') {
|
|
156
|
+
current.held = false;
|
|
157
|
+
current.shown = null;
|
|
158
|
+
if (state.proposal) closeProposal(inst);
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
if (!current.hasTopology) { current.held = true; return undefined; } // a proposal is laid over a map: it opens when there is one
|
|
162
|
+
current.held = false;
|
|
163
|
+
const view = current.proposalView;
|
|
164
|
+
if (typeof wanted === 'string') {
|
|
165
|
+
const key = `${wanted}\u0000${current.source || ''}`;
|
|
166
|
+
if (current.shown === key && state.proposal) return undefined; // already open (the piece answers true too)
|
|
167
|
+
current.shown = key;
|
|
168
|
+
return proposalPiece.update({ proposal: wanted, source: current.source, view });
|
|
169
|
+
}
|
|
170
|
+
if (current.shown === wanted && state.proposal) return undefined;
|
|
171
|
+
current.shown = wanted;
|
|
172
|
+
// With no server to ask (no `base`, no `fetch`) the object is all there is: its name and source would only send the pieces to the host's own origin for a PR's checks and reviews
|
|
173
|
+
const named = serverless ? {} : { source: current.source, slug: current.slug, sha256: current.sha256 };
|
|
174
|
+
proposalPiece.update({ proposal: wanted, ...named, view });
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The topology changed: the base map is the host's new one, laid out and fitted; an open proposal is laid over it again */
|
|
179
|
+
function applyTopology(topology) {
|
|
180
|
+
current.hasTopology = setTopology(inst, topology);
|
|
181
|
+
// A topology with nothing on it says so in words, never a blank box (no word before a topology is handed in: the host may still be loading it)
|
|
182
|
+
const empty = box.querySelector('.hx-review-empty');
|
|
183
|
+
empty.textContent = current.hasTopology ? '' : EMPTY_WORDS;
|
|
184
|
+
empty.hidden = current.hasTopology;
|
|
185
|
+
if (!current.hasTopology) { inst.map.render(); return; }
|
|
186
|
+
layoutMap(inst);
|
|
187
|
+
if (state.proposal) rebuildProposalMap(inst, undefined, { fit: true });
|
|
188
|
+
else mapPiece.fit();
|
|
189
|
+
inst.map.render();
|
|
190
|
+
inst.map.ensureFlowLoop();
|
|
191
|
+
if (current.held) applyProposal();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The map's view (whole map or the data-flow lanes): laid out again, the camera fitted, a playing scenario ended (as the page's switch does) */
|
|
195
|
+
function setMapView(view) {
|
|
196
|
+
const next = view === 'dataflow' ? 'dataflow' : 'orbit';
|
|
197
|
+
if (state.view === next) return;
|
|
198
|
+
state.view = next;
|
|
199
|
+
inst.emit('scenario:clear');
|
|
200
|
+
inst.touchScene();
|
|
201
|
+
if (state.nodes.length) {
|
|
202
|
+
setMap(inst, state.mapNodes, state.mapEdges);
|
|
203
|
+
mapPiece.fit();
|
|
204
|
+
inst.map.ensureFlowLoop();
|
|
205
|
+
}
|
|
206
|
+
inst.emit('view', state.view);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The words of `view`: the proposal's (before, diff, after) or the map's (map, dataflow); the two sets do not meet */
|
|
210
|
+
function applyView(view) {
|
|
211
|
+
if (PROPOSAL_VIEWS.includes(view)) {
|
|
212
|
+
current.proposalView = view;
|
|
213
|
+
if (state.proposal) proposalPiece.update({ view });
|
|
214
|
+
} else if (MAP_VIEWS.includes(view)) setMapView(view);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function applyConfig(config) {
|
|
218
|
+
if (!config || typeof config !== 'object') return;
|
|
219
|
+
if ('layers' in config) setProjectLayers(inst, config.layers);
|
|
220
|
+
if (config.theme) mapPiece.applyTheme(config.theme);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Applies what changed in `next` (the options above). Only the keys present are looked at.
|
|
225
|
+
* @returns {Promise<boolean>|undefined} when a proposal is fetched: whether it opened
|
|
226
|
+
*/
|
|
227
|
+
function update(next = {}) {
|
|
228
|
+
if (ended) return undefined;
|
|
229
|
+
let again = false;
|
|
230
|
+
if ('strings' in next) { setStrings(inst, next.strings); applyStrings(inst, box); again = true; }
|
|
231
|
+
if ('config' in next) applyConfig(next.config);
|
|
232
|
+
if ('theme' in next) mapPiece.update({ theme: next.theme });
|
|
233
|
+
if ('checker' in next) changesPiece.update({ checker: next.checker });
|
|
234
|
+
if ('topology' in next && next.topology !== current.topology) { current.topology = next.topology; applyTopology(next.topology); }
|
|
235
|
+
let result;
|
|
236
|
+
const asked = ['proposal', 'source', 'slug', 'sha256'].some((k) => k in next);
|
|
237
|
+
if (asked) {
|
|
238
|
+
if ('source' in next) current.source = next.source || null;
|
|
239
|
+
if ('slug' in next) current.slug = next.slug || null;
|
|
240
|
+
if ('sha256' in next) current.sha256 = next.sha256 || null;
|
|
241
|
+
if ('proposal' in next) { current.proposal = next.proposal; current.shown = null; }
|
|
242
|
+
if ('view' in next && PROPOSAL_VIEWS.includes(next.view)) current.proposalView = next.view;
|
|
243
|
+
result = applyProposal();
|
|
244
|
+
}
|
|
245
|
+
if ('view' in next && !(asked && PROPOSAL_VIEWS.includes(next.view))) applyView(next.view);
|
|
246
|
+
if ('node' in next) mapPiece.update({ node: next.node });
|
|
247
|
+
if (again) redraw();
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Ends the piece: every piece in it, the box, and the instance if the piece made it. Safe to call twice. */
|
|
252
|
+
function destroy() {
|
|
253
|
+
if (ended) return;
|
|
254
|
+
ended = true;
|
|
255
|
+
stopAsking();
|
|
256
|
+
for (const piece of [decisionPiece, changesPiece, proposalPiece, nodePanel, mapPiece]) piece.destroy();
|
|
257
|
+
setPhoneBox(inst, null);
|
|
258
|
+
box.remove();
|
|
259
|
+
if (ownsInstance) inst.destroy();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// What was handed in at mount is applied as an update, in the order update() keeps (strings, theme and the checker were taken above)
|
|
263
|
+
const first = {};
|
|
264
|
+
for (const key of ['config', 'topology', 'proposal', 'source', 'slug', 'sha256', 'view', 'node']) if (options[key] !== undefined) first[key] = options[key];
|
|
265
|
+
update(first);
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
inst,
|
|
269
|
+
elements: [box],
|
|
270
|
+
map: mapPiece,
|
|
271
|
+
proposal: proposalPiece,
|
|
272
|
+
changes: changesPiece,
|
|
273
|
+
decision: decisionPiece,
|
|
274
|
+
nodePanel,
|
|
275
|
+
update,
|
|
276
|
+
destroy,
|
|
277
|
+
/** The whole map in view */
|
|
278
|
+
fit: () => mapPiece.fit(),
|
|
279
|
+
};
|
|
280
|
+
}
|
package/explorer/view.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { state, touchScene, pageInstance } from './state.js';
|
|
9
|
-
import { computeDegreeCentrality
|
|
9
|
+
import { computeDegreeCentrality } from './layout.js';
|
|
10
|
+
import { layoutMap } from './engine/topology.js';
|
|
10
11
|
import { buildDataFlow } from './flows.js';
|
|
11
12
|
import { render, fitGraphToViewport, fitPadding, ensureFlowLoop } from './render.js';
|
|
12
|
-
import { orderAddedLast
|
|
13
|
+
import { orderAddedLast } from './proposal-model.js';
|
|
13
14
|
import { renderLayerToggles } from './layers.js';
|
|
14
15
|
import { clearScenario } from './scenario-ui.js';
|
|
15
16
|
import { measureParams } from './bench.js';
|
|
@@ -80,64 +81,10 @@ export function setMap(nodes, edges) {
|
|
|
80
81
|
renderLayerToggles();
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
/** Where the nodes sit: the House view's plan here (house-model.js, PHY-11), every other view the engine's one layout (engine/topology.js `layoutMap`) */
|
|
83
85
|
function applyLayout() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (state.view === 'dataflow') {
|
|
87
|
-
state.flow.tiers.forEach((t) => t.nodes.forEach((n) => { n.r = Math.min(n.r, 13); })); // ... all small in the lanes
|
|
88
|
-
if (!(state.proposal && laneLayoutAround())) computeLaneLayout(state.flow);
|
|
89
|
-
} else if (state.proposal || state.nodes.some((n) => n.live)) {
|
|
90
|
-
layoutOrbitAround(); // the code map keeps its places; what a proposal adds and the live layer are placed beside it
|
|
91
|
-
} else {
|
|
92
|
-
layoutOrbit();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* The data-flow lanes while a proposal is open: the base map is laid out on its own and pinned, and
|
|
98
|
-
* the added nodes take free cells (pinLanes). False when that cannot be done, and the lanes are laid out afresh.
|
|
99
|
-
*/
|
|
100
|
-
function laneLayoutAround() {
|
|
101
|
-
const applied = { nodes: state.nodes, edges: state.edges };
|
|
102
|
-
const laid = state.baseNodes.map((n) => ({ ...n }));
|
|
103
|
-
state.nodes = laid;
|
|
104
|
-
state.edges = state.baseEdges;
|
|
105
|
-
computeDegreeCentrality();
|
|
106
|
-
const baseFlow = buildDataFlow(laid, state.baseEdges);
|
|
107
|
-
baseFlow.tiers.forEach((t) => t.nodes.forEach((n) => { n.r = Math.min(n.r, 13); }));
|
|
108
|
-
computeLaneLayout(baseFlow);
|
|
109
|
-
state.nodes = applied.nodes;
|
|
110
|
-
state.edges = applied.edges;
|
|
111
|
-
const pinned = pinLanes(state.flow, baseFlow);
|
|
112
|
-
touchScene();
|
|
113
|
-
return pinned;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The orbit layout while a proposal is open: the base map is laid out on its own, exactly as it is
|
|
118
|
-
* with no proposal, and the nodes that were there keep those places and sizes; only the added ones
|
|
119
|
-
* are placed, next to their parent (placeAddedNodes). So opening a proposal, switching between
|
|
120
|
-
* Before, Diff and After, and closing it never move a node that was already on the map.
|
|
121
|
-
*/
|
|
122
|
-
function layoutOrbitAround() {
|
|
123
|
-
const applied = { nodes: state.nodes, edges: state.edges };
|
|
124
|
-
const laid = state.baseNodes.map((n) => ({ ...n }));
|
|
125
|
-
state.nodes = laid;
|
|
126
|
-
state.edges = state.baseEdges;
|
|
127
|
-
computeDegreeCentrality();
|
|
128
|
-
layoutOrbit(); // also sets the rings
|
|
129
|
-
const at = new Map(laid.map((n) => [n.id, n]));
|
|
130
|
-
|
|
131
|
-
state.nodes = applied.nodes;
|
|
132
|
-
state.edges = applied.edges;
|
|
133
|
-
computeDegreeCentrality();
|
|
134
|
-
state.nodes.forEach((n) => {
|
|
135
|
-
const was = at.get(n.id);
|
|
136
|
-
if (was) { n.x = was.x; n.y = was.y; n.r = was.r; }
|
|
137
|
-
});
|
|
138
|
-
placeAddedNodes(state.nodes, state.edges);
|
|
139
|
-
placeLiveNodes(state.nodes, state.edges);
|
|
140
|
-
touchScene();
|
|
86
|
+
if (state.view === 'house') { computeDegreeCentrality(); applyHouseLayout(state); return; }
|
|
87
|
+
layoutMap(pageInstance(), { placeLive: placeLiveNodes }); // the live layer is the page's (live-model.js): the engine places it with this
|
|
141
88
|
}
|
|
142
89
|
|
|
143
90
|
/** Switches between 'orbit' and 'dataflow'; the camera refits and the preset button follows */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.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)",
|