@crewlethq/ui 0.121.1 → 0.123.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/README.md +45 -2
- package/dist/Charts/StackedRing.d.ts +40 -0
- package/dist/Charts/TimeSeries.d.ts +8 -1
- package/dist/Charts/index.d.ts +2 -0
- package/dist/Charts/index.js +1 -1
- package/dist/{Charts-UJKADWXE.css → Charts-4VQ7T3GB.css} +85 -0
- package/dist/DataGrid/DataGrid.d.ts +11 -1
- package/dist/DataGrid/index.d.ts +1 -1
- package/dist/DataGrid/index.js +1 -1
- package/dist/{DataGrid-7KUUYSHA.css → DataGrid-KAFVH4B3.css} +3 -1
- package/dist/DeepWorkCard/index.js +2 -2
- package/dist/Fullscreen/FullscreenToggle.d.ts +21 -0
- package/dist/Fullscreen/index.d.ts +2 -0
- package/dist/Fullscreen/index.js +11 -1
- package/dist/GraphCanvas/GraphCanvas.d.ts +268 -0
- package/dist/GraphCanvas/index.d.ts +9 -0
- package/dist/GraphCanvas/index.js +21 -0
- package/dist/GraphCanvas/layout.d.ts +231 -0
- package/dist/GraphCanvas/reach.d.ts +27 -0
- package/dist/GraphCanvas/walk.d.ts +21 -0
- package/dist/GraphCanvas-UZPZRP6S.css +793 -0
- package/dist/IconTile/IconTile.d.ts +26 -18
- package/dist/IconTile/index.d.ts +1 -1
- package/dist/IconTile/index.js +1 -1
- package/dist/IconTile-6OSCIHYU.css +112 -0
- package/dist/ObjectHeader/ObjectHeader.d.ts +17 -2
- package/dist/ObjectHeader/index.d.ts +2 -2
- package/dist/ObjectHeader/index.js +1 -1
- package/dist/{ObjectHeader-5RK5YAUK.css → ObjectHeader-BH7OBEAL.css} +12 -0
- package/dist/OpenInAppCard/index.js +2 -2
- package/dist/OrgTable/index.js +5 -5
- package/dist/PropertyList/index.js +2 -2
- package/dist/ReviewList/index.js +2 -2
- package/dist/RichEditor/index.js +1 -1
- package/dist/SetupWizard/index.js +2 -2
- package/dist/StatusLegend/StatusLegend.d.ts +1 -1
- package/dist/StatusLegend/index.js +1 -1
- package/dist/{StatusLegend-HVMKJQFY.css → StatusLegend-DMSTS2NG.css} +9 -0
- package/dist/TreeGrid/index.js +2 -2
- package/dist/{chunk-W5XCNEZC.js → chunk-3JLG6KRU.js} +23 -2
- package/dist/{chunk-65AMIQSW.js → chunk-4PEPSGCZ.js} +4 -2
- package/dist/{chunk-AGVGX52B.js → chunk-7XYU5PSQ.js} +1 -1
- package/dist/{chunk-5LIWAA7S.js → chunk-CXFMNOPV.js} +15 -6
- package/dist/chunk-DSBKVP73.js +2138 -0
- package/dist/{chunk-3RKS3DLF.js → chunk-ENYHABQJ.js} +1 -1
- package/dist/{chunk-S2ZUAI6C.js → chunk-EWJOBD25.js} +2 -2
- package/dist/{chunk-KZTR3V2P.js → chunk-J44ZIWGH.js} +11 -3
- package/dist/{chunk-X5YI6QLW.js → chunk-NOKZULW3.js} +1 -1
- package/dist/{chunk-ZOMTCEHR.js → chunk-OFNJE4BN.js} +6 -1
- package/dist/{chunk-75O3HCCD.js → chunk-T4TKY4VZ.js} +1 -1
- package/dist/chunk-VRVNLJUA.js +46 -0
- package/dist/{chunk-MNTN5ESE.js → chunk-ZY5322MJ.js} +77 -3
- package/dist/generated/index.d.ts +1 -0
- package/dist/generated/index.js +42 -41
- package/dist/index.js +42 -41
- package/dist/styles.css +1137 -154
- package/package.json +3 -3
- package/dist/IconTile-G52XZVR4.css +0 -33
- package/dist/chunk-3LI4TRUR.js +0 -22
- package/dist/{Editor-JCAYNXQX.js → Editor-SBHTMAEK.js} +1 -1
- package/dist/{chunk-WLL3PFI3.js → chunk-2DZV4PHK.js} +1 -1
- package/dist/{chunk-4Z3AGYOB.js → chunk-P42LNYRX.js} +1 -1
- /package/dist/{chunk-33NGH63Z.js → chunk-QV3WVNRA.js} +0 -0
|
@@ -0,0 +1,2138 @@
|
|
|
1
|
+
import { useMeasuredSizes, isTypeAheadKey, typeAheadBuffer } from './chunk-MY374UUD.js';
|
|
2
|
+
import { FilterChip } from './chunk-L6HUVA33.js';
|
|
3
|
+
import { FullscreenToggle } from './chunk-3JLG6KRU.js';
|
|
4
|
+
import { fitView, CANVAS_FIT_PADDING, Canvas } from './chunk-GKHZSNIV.js';
|
|
5
|
+
import { Text } from './chunk-XLMURU75.js';
|
|
6
|
+
import { LayerHost } from './chunk-FIX72ZEC.js';
|
|
7
|
+
import { VisuallyHidden } from './chunk-RRRK2KB6.js';
|
|
8
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
9
|
+
import './GraphCanvas-UZPZRP6S.css';
|
|
10
|
+
import { memo, useMemo, useId, useState, useCallback, useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
|
|
11
|
+
import { ChevronDownGlyph, ChevronRightGlyph, TriangleAlertGlyph, CircleAlertGlyph, InfoGlyph } from '@crewlethq/icons/glyphs';
|
|
12
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
// src/GraphCanvas/layout.ts
|
|
15
|
+
var GRAPH_ORDER_SWEEPS = 8;
|
|
16
|
+
var TRACK_STEP = 6;
|
|
17
|
+
var STREET_TRACK_STEP = 4;
|
|
18
|
+
var CORNER = 6;
|
|
19
|
+
var ARROW_LENGTH = 7;
|
|
20
|
+
var ARROW_HALF = 3.5;
|
|
21
|
+
var PORT_INSET = 8;
|
|
22
|
+
function graphItemKey(kind, id) {
|
|
23
|
+
return `${kind}:${id}`;
|
|
24
|
+
}
|
|
25
|
+
function layoutGraph(input, metrics) {
|
|
26
|
+
const { bands, nodes, open } = input;
|
|
27
|
+
const groups = input.groups ?? [];
|
|
28
|
+
const laneBand = /* @__PURE__ */ new Map();
|
|
29
|
+
bands.forEach(
|
|
30
|
+
(band, b) => band.lanes.forEach((lane) => {
|
|
31
|
+
if (laneBand.has(lane)) throw new Error(`GraphCanvas: lane "${lane}" is listed twice`);
|
|
32
|
+
laneBand.set(lane, b);
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
const groupLane = /* @__PURE__ */ new Map();
|
|
36
|
+
for (const group of groups) {
|
|
37
|
+
if (groupLane.has(group.id)) throw new Error(`GraphCanvas: group "${group.id}" is listed twice`);
|
|
38
|
+
if (!laneBand.has(group.lane))
|
|
39
|
+
throw new Error(`GraphCanvas: group "${group.id}" is in unknown lane "${group.lane}"`);
|
|
40
|
+
groupLane.set(group.id, group.lane);
|
|
41
|
+
}
|
|
42
|
+
const seen = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const node of nodes) {
|
|
44
|
+
if (seen.has(node.id)) throw new Error(`GraphCanvas: entry "${node.id}" is listed twice`);
|
|
45
|
+
seen.add(node.id);
|
|
46
|
+
if (!laneBand.has(node.lane)) throw new Error(`GraphCanvas: entry "${node.id}" is in unknown lane "${node.lane}"`);
|
|
47
|
+
if (node.group !== void 0 && groupLane.get(node.group) !== node.lane) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`GraphCanvas: entry "${node.id}" names group "${node.group}", which is not in lane "${node.lane}"`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const blocksOf = /* @__PURE__ */ new Map();
|
|
54
|
+
const groupBlock = /* @__PURE__ */ new Map();
|
|
55
|
+
for (const band of bands) for (const lane of band.lanes) blocksOf.set(lane, []);
|
|
56
|
+
nodes.forEach((node, index) => {
|
|
57
|
+
const list = blocksOf.get(node.lane);
|
|
58
|
+
if (node.group === void 0) {
|
|
59
|
+
list.push({ kind: "loose", id: node.id, members: [node.id], index });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let block = groupBlock.get(node.group);
|
|
63
|
+
if (!block) {
|
|
64
|
+
block = { kind: open(node.group) ? "group" : "closed", id: node.group, members: [], index };
|
|
65
|
+
groupBlock.set(node.group, block);
|
|
66
|
+
list.push(block);
|
|
67
|
+
}
|
|
68
|
+
block.members.push(node.id);
|
|
69
|
+
});
|
|
70
|
+
const keyOfNode = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const blocks of blocksOf.values()) {
|
|
72
|
+
for (const block of blocks) {
|
|
73
|
+
for (const id of block.members) {
|
|
74
|
+
keyOfNode.set(id, block.kind === "closed" ? graphItemKey("summary", block.id) : graphItemKey("node", id));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const allLanes = bands.flatMap((band) => band.lanes);
|
|
79
|
+
const laneNumber = new Map(allLanes.map((lane, i) => [lane, i]));
|
|
80
|
+
const itemIndex = /* @__PURE__ */ new Map();
|
|
81
|
+
const itemLane = [];
|
|
82
|
+
for (const lane of allLanes) {
|
|
83
|
+
for (const block of blocksOf.get(lane)) {
|
|
84
|
+
const keys = block.kind === "closed" ? [graphItemKey("summary", block.id)] : block.members.map((id) => graphItemKey("node", id));
|
|
85
|
+
for (const key of keys) {
|
|
86
|
+
itemIndex.set(key, itemLane.length);
|
|
87
|
+
itemLane.push(laneNumber.get(lane));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const adjacent = itemLane.map(() => []);
|
|
92
|
+
for (const edge of input.ordering ?? input.edges) {
|
|
93
|
+
const a = itemIndex.get(keyOfNode.get(edge.from) ?? "");
|
|
94
|
+
const b = itemIndex.get(keyOfNode.get(edge.to) ?? "");
|
|
95
|
+
if (a === void 0 || b === void 0 || a === b || itemLane[a] === itemLane[b]) continue;
|
|
96
|
+
adjacent[a].push(b);
|
|
97
|
+
adjacent[b].push(a);
|
|
98
|
+
}
|
|
99
|
+
const columnOf = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const node of nodes) if (node.column !== void 0 && node.group === void 0) columnOf.set(node.id, node.column);
|
|
101
|
+
const pitch = metrics.cardHeight + metrics.rowGap;
|
|
102
|
+
const emptyRowsOf = (lane) => {
|
|
103
|
+
const height = input.emptyHeights?.get(lane);
|
|
104
|
+
if (height === void 0 || height <= 0) return 1;
|
|
105
|
+
return Math.max(1, Math.ceil((height + metrics.rowGap) / pitch));
|
|
106
|
+
};
|
|
107
|
+
const placeLane = (lane, span = laneCols.get(lane).span) => {
|
|
108
|
+
const blocks = blocksOf.get(lane);
|
|
109
|
+
const cells = [];
|
|
110
|
+
if (blocks.length === 0) {
|
|
111
|
+
const rows = emptyRowsOf(lane);
|
|
112
|
+
cells.push({ key: graphItemKey("empty", lane), kind: "empty", id: lane, col: 0, row: 0, cols: span, rows });
|
|
113
|
+
return { cells, rows };
|
|
114
|
+
}
|
|
115
|
+
if (span > 1 && blocks.every((block) => block.kind === "loose") && blocks.some((block) => columnOf.has(block.id))) {
|
|
116
|
+
const stacks = Array.from({ length: span }, () => []);
|
|
117
|
+
for (const block of blocks) {
|
|
118
|
+
const named = columnOf.get(block.id);
|
|
119
|
+
let at = 0;
|
|
120
|
+
if (named === void 0) {
|
|
121
|
+
for (let c = 1; c < span; c++) if (stacks[c].length < stacks[at].length) at = c;
|
|
122
|
+
} else at = Math.min(span - 1, Math.max(0, Math.trunc(named)));
|
|
123
|
+
stacks[at].push(block);
|
|
124
|
+
}
|
|
125
|
+
const rows = Math.max(...stacks.map((stack) => stack.length));
|
|
126
|
+
stacks.forEach((stack, c) => {
|
|
127
|
+
const first = Math.floor((rows - stack.length) / 2);
|
|
128
|
+
stack.forEach(
|
|
129
|
+
(block, i) => cells.push({
|
|
130
|
+
key: graphItemKey("node", block.id),
|
|
131
|
+
kind: "node",
|
|
132
|
+
id: block.id,
|
|
133
|
+
col: c,
|
|
134
|
+
row: first + i,
|
|
135
|
+
cols: 1,
|
|
136
|
+
rows: 1
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
return { cells, rows };
|
|
141
|
+
}
|
|
142
|
+
let row = 0;
|
|
143
|
+
let col = 0;
|
|
144
|
+
const cell = (key, kind, id) => {
|
|
145
|
+
cells.push({ key, kind, id, col, row, cols: 1, rows: 1 });
|
|
146
|
+
col += 1;
|
|
147
|
+
if (col === span) {
|
|
148
|
+
col = 0;
|
|
149
|
+
row += 1;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
for (const block of blocks) {
|
|
153
|
+
if (block.kind === "loose") cell(graphItemKey("node", block.id), "node", block.id);
|
|
154
|
+
else if (block.kind === "closed") cell(graphItemKey("summary", block.id), "summary", block.id);
|
|
155
|
+
else {
|
|
156
|
+
if (col > 0) {
|
|
157
|
+
col = 0;
|
|
158
|
+
row += 1;
|
|
159
|
+
}
|
|
160
|
+
cells.push({
|
|
161
|
+
key: graphItemKey("head", block.id),
|
|
162
|
+
kind: "head",
|
|
163
|
+
id: block.id,
|
|
164
|
+
col: 0,
|
|
165
|
+
row,
|
|
166
|
+
cols: span,
|
|
167
|
+
rows: 1
|
|
168
|
+
});
|
|
169
|
+
row += 1;
|
|
170
|
+
for (const id of block.members) cell(graphItemKey("node", id), "node", id);
|
|
171
|
+
if (col > 0) {
|
|
172
|
+
col = 0;
|
|
173
|
+
row += 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (col > 0) row += 1;
|
|
178
|
+
return { cells, rows: row };
|
|
179
|
+
};
|
|
180
|
+
const asked = (lane) => Math.max(1, Math.trunc(input.laneColumns?.get(lane) ?? 1));
|
|
181
|
+
const widthOf = (band) => band.lanes.reduce((sum, lane) => sum + asked(lane), 0);
|
|
182
|
+
const columns = Math.max(1, ...bands.map(widthOf));
|
|
183
|
+
const laneCols = /* @__PURE__ */ new Map();
|
|
184
|
+
for (const band of bands) {
|
|
185
|
+
const even = Math.floor((columns - widthOf(band)) / Math.max(1, band.lanes.length));
|
|
186
|
+
const spans = band.lanes.map((lane) => asked(lane) + even);
|
|
187
|
+
const rowsAt = (i, span) => {
|
|
188
|
+
const lane = band.lanes[i];
|
|
189
|
+
return blocksOf.get(lane).length === 0 ? 1 : placeLane(lane, span).rows;
|
|
190
|
+
};
|
|
191
|
+
for (let spare = columns - spans.reduce((sum, span) => sum + span, 0); spare > 0; spare--) {
|
|
192
|
+
let pick = 0;
|
|
193
|
+
let best = [-1, -1, -Infinity];
|
|
194
|
+
spans.forEach((span, i) => {
|
|
195
|
+
const now = rowsAt(i, span);
|
|
196
|
+
const gains = now > rowsAt(i, span + 1);
|
|
197
|
+
const score = [gains ? 1 : 0, gains ? now : 0, -span];
|
|
198
|
+
if (score[0] > best[0] || score[0] === best[0] && (score[1] > best[1] || score[1] === best[1] && score[2] > best[2])) {
|
|
199
|
+
best = score;
|
|
200
|
+
pick = i;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
spans[pick] += 1;
|
|
204
|
+
}
|
|
205
|
+
let col = 0;
|
|
206
|
+
band.lanes.forEach((lane, i) => {
|
|
207
|
+
laneCols.set(lane, { col, span: spans[i] });
|
|
208
|
+
col += spans[i];
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const rank = new Float64Array(itemLane.length);
|
|
212
|
+
const rankLane = (lane) => {
|
|
213
|
+
const b = laneBand.get(lane);
|
|
214
|
+
const { col } = laneCols.get(lane);
|
|
215
|
+
for (const cell of placeLane(lane).cells) {
|
|
216
|
+
const index = itemIndex.get(cell.key);
|
|
217
|
+
if (index !== void 0) rank[index] = b * 1e6 + cell.row * columns + col + cell.col;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
allLanes.forEach(rankLane);
|
|
221
|
+
const barycentre = (index) => {
|
|
222
|
+
const list = adjacent[index];
|
|
223
|
+
if (list.length === 0) return NaN;
|
|
224
|
+
let sum = 0;
|
|
225
|
+
for (const other of list) sum += rank[other];
|
|
226
|
+
return sum / list.length;
|
|
227
|
+
};
|
|
228
|
+
for (let sweep = 0; sweep < GRAPH_ORDER_SWEEPS; sweep++) {
|
|
229
|
+
const order = sweep % 2 === 0 ? allLanes : [...allLanes].reverse();
|
|
230
|
+
for (const lane of order) {
|
|
231
|
+
const blocks = blocksOf.get(lane);
|
|
232
|
+
if (blocks.length === 0) continue;
|
|
233
|
+
const keyed = blocks.map((block, position) => {
|
|
234
|
+
const indices = block.kind === "closed" ? [itemIndex.get(graphItemKey("summary", block.id))] : block.members.map((id) => itemIndex.get(graphItemKey("node", id)));
|
|
235
|
+
const bary = indices.map(barycentre);
|
|
236
|
+
if (block.kind === "group") {
|
|
237
|
+
const scored = block.members.map((id, i) => ({
|
|
238
|
+
id,
|
|
239
|
+
i,
|
|
240
|
+
at: Number.isNaN(bary[i]) ? rank[indices[i]] : bary[i]
|
|
241
|
+
}));
|
|
242
|
+
scored.sort((a, b) => a.at - b.at || a.i - b.i);
|
|
243
|
+
block.members = scored.map((one) => one.id);
|
|
244
|
+
}
|
|
245
|
+
let sum = 0;
|
|
246
|
+
let count = 0;
|
|
247
|
+
for (const value of bary) {
|
|
248
|
+
if (Number.isNaN(value)) continue;
|
|
249
|
+
sum += value;
|
|
250
|
+
count += 1;
|
|
251
|
+
}
|
|
252
|
+
return { block, position, at: count > 0 ? sum / count : rank[indices[0]] };
|
|
253
|
+
});
|
|
254
|
+
keyed.sort((a, b) => a.at - b.at || a.position - b.position);
|
|
255
|
+
blocksOf.set(
|
|
256
|
+
lane,
|
|
257
|
+
keyed.map((one) => one.block)
|
|
258
|
+
);
|
|
259
|
+
rankLane(lane);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const { cardWidth, cardHeight, gutter, rowGap, laneHead, bandHead, bandGap, lanePad, margin } = metrics;
|
|
263
|
+
const colX = Array.from({ length: columns }, (_, c) => margin + gutter / 2 + c * (cardWidth + gutter));
|
|
264
|
+
const channelX = Array.from({ length: columns + 1 }, (_, c) => margin + c * (cardWidth + gutter));
|
|
265
|
+
const placedLanes = new Map(allLanes.map((lane) => [lane, placeLane(lane)]));
|
|
266
|
+
const bandRows = bands.map((band) => Math.max(1, ...band.lanes.map((lane) => placedLanes.get(lane).rows)));
|
|
267
|
+
const bandsPlaced = [];
|
|
268
|
+
const bandRowsTop = [];
|
|
269
|
+
let y = margin;
|
|
270
|
+
bands.forEach((band, b) => {
|
|
271
|
+
const title = band.titled ? { x: channelX[0], y, width: channelX[columns] - channelX[0], height: bandHead } : null;
|
|
272
|
+
if (band.titled) y += bandHead;
|
|
273
|
+
const rowsTop = y + laneHead;
|
|
274
|
+
bandRowsTop.push(rowsTop);
|
|
275
|
+
bandsPlaced.push({ id: band.id, index: b, title, rowsTop, rows: bandRows[b] });
|
|
276
|
+
y = rowsTop + bandRows[b] * pitch - rowGap + lanePad + (b < bands.length - 1 ? bandGap : 0);
|
|
277
|
+
});
|
|
278
|
+
const bounds = { x: 0, y: 0, width: channelX[columns] + margin, height: y + margin };
|
|
279
|
+
const items = [];
|
|
280
|
+
const itemByKey = /* @__PURE__ */ new Map();
|
|
281
|
+
const lanes = [];
|
|
282
|
+
const occupied = bands.map((_, b) => new Uint8Array(bandRows[b] * columns));
|
|
283
|
+
const rowY = (b, row) => bandRowsTop[b] + row * pitch;
|
|
284
|
+
for (const lane of allLanes) {
|
|
285
|
+
const b = laneBand.get(lane);
|
|
286
|
+
const { col, span } = laneCols.get(lane);
|
|
287
|
+
const { cells } = placedLanes.get(lane);
|
|
288
|
+
const left = colX[col];
|
|
289
|
+
const right = colX[col + span - 1] + cardWidth;
|
|
290
|
+
const rowsTop = bandRowsTop[b];
|
|
291
|
+
const rowsBottom = rowsTop + bandRows[b] * pitch - rowGap;
|
|
292
|
+
const head = { x: left, y: rowsTop - laneHead, width: right - left, height: laneHead };
|
|
293
|
+
const keys = [];
|
|
294
|
+
for (const cell of cells) {
|
|
295
|
+
const x = colX[col + cell.col];
|
|
296
|
+
const width = cell.cols === 1 || cell.kind === "head" ? cardWidth : colX[col + cell.col + cell.cols - 1] + cardWidth - x;
|
|
297
|
+
const top = rowY(b, cell.row) + (cell.kind === "head" ? cardHeight / 2 : 0);
|
|
298
|
+
const item = {
|
|
299
|
+
key: cell.key,
|
|
300
|
+
kind: cell.kind,
|
|
301
|
+
id: cell.id,
|
|
302
|
+
lane,
|
|
303
|
+
band: b,
|
|
304
|
+
col: col + cell.col,
|
|
305
|
+
row: cell.row,
|
|
306
|
+
cols: cell.cols,
|
|
307
|
+
rows: cell.rows,
|
|
308
|
+
x,
|
|
309
|
+
y: top,
|
|
310
|
+
width,
|
|
311
|
+
height: cell.kind === "head" ? cardHeight / 2 : cell.rows * pitch - rowGap
|
|
312
|
+
};
|
|
313
|
+
items.push(item);
|
|
314
|
+
itemByKey.set(item.key, item);
|
|
315
|
+
keys.push(item.key);
|
|
316
|
+
for (let r = cell.row; r < cell.row + cell.rows; r++) {
|
|
317
|
+
for (let c = item.col; c < item.col + cell.cols; c++) occupied[b][r * columns + c] = 1;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const count = (blocksOf.get(lane) ?? []).reduce((sum, block) => sum + block.members.length, 0);
|
|
321
|
+
lanes.push({
|
|
322
|
+
id: lane,
|
|
323
|
+
band: b,
|
|
324
|
+
col,
|
|
325
|
+
span,
|
|
326
|
+
rows: placedLanes.get(lane).rows,
|
|
327
|
+
panel: {
|
|
328
|
+
x: left - lanePad,
|
|
329
|
+
y: head.y,
|
|
330
|
+
width: right - left + 2 * lanePad,
|
|
331
|
+
height: rowsBottom + lanePad - head.y
|
|
332
|
+
},
|
|
333
|
+
head,
|
|
334
|
+
items: keys,
|
|
335
|
+
count
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
const groupsPlaced = [];
|
|
339
|
+
const boxBottoms = [];
|
|
340
|
+
for (const lane of allLanes) {
|
|
341
|
+
for (const block of blocksOf.get(lane)) {
|
|
342
|
+
if (block.kind === "loose") continue;
|
|
343
|
+
if (block.kind === "closed") {
|
|
344
|
+
groupsPlaced.push({ id: block.id, lane, open: false, box: null, members: [...block.members] });
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const head = itemByKey.get(graphItemKey("head", block.id));
|
|
348
|
+
const last = block.members.reduce((bottom2, id) => {
|
|
349
|
+
const item = itemByKey.get(graphItemKey("node", id));
|
|
350
|
+
return Math.max(bottom2, item.row);
|
|
351
|
+
}, head.row);
|
|
352
|
+
const { col, span } = laneCols.get(lane);
|
|
353
|
+
const top = head.y;
|
|
354
|
+
const bottom = rowY(head.band, last) + cardHeight + lanePad / 2;
|
|
355
|
+
groupsPlaced.push({
|
|
356
|
+
id: block.id,
|
|
357
|
+
lane,
|
|
358
|
+
open: true,
|
|
359
|
+
box: {
|
|
360
|
+
x: colX[col] - lanePad / 2,
|
|
361
|
+
y: top,
|
|
362
|
+
width: colX[col + span - 1] + cardWidth - colX[col] + lanePad,
|
|
363
|
+
height: bottom - top
|
|
364
|
+
},
|
|
365
|
+
members: [...block.members]
|
|
366
|
+
});
|
|
367
|
+
boxBottoms.push({ band: head.band, col, span, row: last });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const streets = [];
|
|
371
|
+
const empties = items.filter((item) => item.kind === "empty");
|
|
372
|
+
bands.forEach((_, b) => {
|
|
373
|
+
for (let row = 0; row < bandRows[b]; row++) {
|
|
374
|
+
const dirty = new Uint8Array(columns);
|
|
375
|
+
const blocked = new Uint8Array(columns);
|
|
376
|
+
for (const box of boxBottoms) {
|
|
377
|
+
if (box.band !== b || box.row !== row) continue;
|
|
378
|
+
for (let c = box.col; c < box.col + box.span; c++) dirty[c] = 1;
|
|
379
|
+
}
|
|
380
|
+
for (const empty of empties) {
|
|
381
|
+
if (empty.band !== b || row < empty.row || row >= empty.row + empty.rows - 1) continue;
|
|
382
|
+
for (let c = empty.col; c < empty.col + empty.cols; c++) blocked[c] = 1;
|
|
383
|
+
}
|
|
384
|
+
streets.push({ y: rowY(b, row) + cardHeight + rowGap / 2, band: b, gap: -1, dirty, blocked });
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
bandsPlaced.forEach((band, b) => {
|
|
388
|
+
if (b === 0) return;
|
|
389
|
+
const above = bandRowsTop[b - 1] + bandRows[b - 1] * pitch - rowGap + lanePad;
|
|
390
|
+
const below = band.title ? band.title.y : band.rowsTop - laneHead;
|
|
391
|
+
streets.push({
|
|
392
|
+
y: (above + below) / 2,
|
|
393
|
+
band: -1,
|
|
394
|
+
gap: b,
|
|
395
|
+
dirty: new Uint8Array(columns),
|
|
396
|
+
blocked: new Uint8Array(columns)
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
streets.sort((a, b) => a.y - b.y);
|
|
400
|
+
const bandStreets = bands.map(() => []);
|
|
401
|
+
const gapStreets = /* @__PURE__ */ new Map();
|
|
402
|
+
streets.forEach((street, i) => {
|
|
403
|
+
if (street.band >= 0) bandStreets[street.band].push(i);
|
|
404
|
+
else gapStreets.set(street.gap, i);
|
|
405
|
+
});
|
|
406
|
+
const grid = { colX, channelX, streets, bandStreets, gapStreets, occupied, bandRows, bandRowsTop };
|
|
407
|
+
const itemOfNode = keyOfNode;
|
|
408
|
+
const partial = { metrics, columns, itemByKey, itemOfNode, grid };
|
|
409
|
+
const routed = routeAll(partial, input.edges);
|
|
410
|
+
return {
|
|
411
|
+
bounds,
|
|
412
|
+
metrics,
|
|
413
|
+
columns,
|
|
414
|
+
bands: bandsPlaced,
|
|
415
|
+
lanes,
|
|
416
|
+
laneById: new Map(lanes.map((lane) => [lane.id, lane])),
|
|
417
|
+
items,
|
|
418
|
+
itemByKey,
|
|
419
|
+
itemOfNode,
|
|
420
|
+
groups: groupsPlaced,
|
|
421
|
+
groupById: new Map(groupsPlaced.map((group) => [group.id, group])),
|
|
422
|
+
routes: routed.routes,
|
|
423
|
+
routeOfEdge: routed.routeOfEdge,
|
|
424
|
+
grid
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function routeGraphEdges(layout, edges) {
|
|
428
|
+
return routeAll(layout, edges).routes;
|
|
429
|
+
}
|
|
430
|
+
function routeAll(layout, edges) {
|
|
431
|
+
const { itemByKey, itemOfNode, grid, columns, metrics } = layout;
|
|
432
|
+
const plans = /* @__PURE__ */ new Map();
|
|
433
|
+
const routeOfEdge = /* @__PURE__ */ new Map();
|
|
434
|
+
for (const edge of edges) {
|
|
435
|
+
const a = itemOfNode.get(edge.from);
|
|
436
|
+
const b = itemOfNode.get(edge.to);
|
|
437
|
+
if (a === void 0 || b === void 0 || a === b) continue;
|
|
438
|
+
const key = `${a}>${b}`;
|
|
439
|
+
routeOfEdge.set(edge.id, key);
|
|
440
|
+
const known = plans.get(key);
|
|
441
|
+
if (known) {
|
|
442
|
+
known.edges.push(edge.id);
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
plans.set(key, plan(key, itemByKey.get(a), itemByKey.get(b), edge.id, grid, columns, metrics));
|
|
446
|
+
}
|
|
447
|
+
const list = [...plans.values()];
|
|
448
|
+
const sides = /* @__PURE__ */ new Map();
|
|
449
|
+
const attach = (item, side, entry) => {
|
|
450
|
+
const key = `${item.key}|${side}`;
|
|
451
|
+
let list2 = sides.get(key);
|
|
452
|
+
if (!list2) sides.set(key, list2 = []);
|
|
453
|
+
list2.push(entry);
|
|
454
|
+
};
|
|
455
|
+
const centre2 = (item) => item.y + item.height / 2;
|
|
456
|
+
for (const one of list) {
|
|
457
|
+
attach(one.from, one.exit, {
|
|
458
|
+
plan: one,
|
|
459
|
+
end: "from",
|
|
460
|
+
toward: one.street === null ? centre2(one.to) : grid.streets[one.street].y
|
|
461
|
+
});
|
|
462
|
+
attach(one.to, one.entry, {
|
|
463
|
+
plan: one,
|
|
464
|
+
end: "to",
|
|
465
|
+
toward: one.street === null ? centre2(one.from) : grid.streets[one.street].y
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
for (const [key, entries] of sides) {
|
|
469
|
+
const item = itemByKey.get(key.slice(0, key.lastIndexOf("|")));
|
|
470
|
+
entries.sort((a, b) => a.toward - b.toward || byText(a.plan.key, b.plan.key));
|
|
471
|
+
const top = item.y + Math.min(PORT_INSET, item.height / 4);
|
|
472
|
+
const room = item.height - 2 * (top - item.y);
|
|
473
|
+
entries.forEach((entry, i) => {
|
|
474
|
+
const y = entries.length === 1 ? centre2(item) : top + room * (i + 0.5) / entries.length;
|
|
475
|
+
if (entry.end === "from") entry.plan.fromY = y;
|
|
476
|
+
else entry.plan.toY = y;
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
const verticals = /* @__PURE__ */ new Map();
|
|
480
|
+
const horizontals = /* @__PURE__ */ new Map();
|
|
481
|
+
const push = (map, key, run) => {
|
|
482
|
+
let runs = map.get(key);
|
|
483
|
+
if (!runs) map.set(key, runs = []);
|
|
484
|
+
runs.push(run);
|
|
485
|
+
};
|
|
486
|
+
for (const one of list) {
|
|
487
|
+
if (one.straight) {
|
|
488
|
+
push(verticals, one.in, {
|
|
489
|
+
plan: one,
|
|
490
|
+
which: "in",
|
|
491
|
+
lo: Math.min(one.fromY, one.toY),
|
|
492
|
+
hi: Math.max(one.fromY, one.toY)
|
|
493
|
+
});
|
|
494
|
+
} else if (one.street === null) {
|
|
495
|
+
push(verticals, one.out, {
|
|
496
|
+
plan: one,
|
|
497
|
+
which: "out",
|
|
498
|
+
lo: Math.min(one.fromY, one.toY),
|
|
499
|
+
hi: Math.max(one.fromY, one.toY)
|
|
500
|
+
});
|
|
501
|
+
} else {
|
|
502
|
+
const sy = grid.streets[one.street].y;
|
|
503
|
+
push(verticals, one.out, { plan: one, which: "out", lo: Math.min(one.fromY, sy), hi: Math.max(one.fromY, sy) });
|
|
504
|
+
push(verticals, one.in, { plan: one, which: "in", lo: Math.min(sy, one.toY), hi: Math.max(sy, one.toY) });
|
|
505
|
+
const ax = grid.channelX[one.out];
|
|
506
|
+
const bx = grid.channelX[one.in];
|
|
507
|
+
push(horizontals, one.street, { plan: one, which: "street", lo: Math.min(ax, bx), hi: Math.max(ax, bx) });
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const verticalRoom = Math.max(0, metrics.gutter - 2 * metrics.lanePad);
|
|
511
|
+
for (const [channel, runs] of verticals) {
|
|
512
|
+
const offsets = assignTracks(runs, TRACK_STEP, verticalRoom);
|
|
513
|
+
runs.forEach((run, i) => {
|
|
514
|
+
const x = grid.channelX[channel] + offsets[i];
|
|
515
|
+
if (run.which === "out") run.plan.outX = x;
|
|
516
|
+
else run.plan.inX = x;
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
for (const [street, runs] of horizontals) {
|
|
520
|
+
const offsets = assignTracks(runs, STREET_TRACK_STEP, Math.max(0, metrics.rowGap - 4));
|
|
521
|
+
runs.forEach((run, i) => {
|
|
522
|
+
run.plan.streetY = grid.streets[street].y + offsets[i];
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
const routes = list.map((one) => {
|
|
526
|
+
const startX = one.exit === "right" ? one.from.x + one.from.width : one.from.x;
|
|
527
|
+
const endX = one.entry === "right" ? one.to.x + one.to.width : one.to.x;
|
|
528
|
+
let points;
|
|
529
|
+
if (one.straight) {
|
|
530
|
+
points = [
|
|
531
|
+
{ x: startX, y: one.fromY },
|
|
532
|
+
{ x: one.inX, y: one.fromY },
|
|
533
|
+
{ x: one.inX, y: one.toY },
|
|
534
|
+
{ x: endX, y: one.toY }
|
|
535
|
+
];
|
|
536
|
+
} else if (one.street === null) {
|
|
537
|
+
points = [
|
|
538
|
+
{ x: startX, y: one.fromY },
|
|
539
|
+
{ x: one.outX, y: one.fromY },
|
|
540
|
+
{ x: one.outX, y: one.toY },
|
|
541
|
+
{ x: endX, y: one.toY }
|
|
542
|
+
];
|
|
543
|
+
} else {
|
|
544
|
+
points = [
|
|
545
|
+
{ x: startX, y: one.fromY },
|
|
546
|
+
{ x: one.outX, y: one.fromY },
|
|
547
|
+
{ x: one.outX, y: one.streetY },
|
|
548
|
+
{ x: one.inX, y: one.streetY },
|
|
549
|
+
{ x: one.inX, y: one.toY },
|
|
550
|
+
{ x: endX, y: one.toY }
|
|
551
|
+
];
|
|
552
|
+
}
|
|
553
|
+
points = simplify(points);
|
|
554
|
+
const direction = one.entry === "right" ? -1 : 1;
|
|
555
|
+
const base = { x: endX - direction * ARROW_LENGTH, y: one.toY };
|
|
556
|
+
const drawn = [...points.slice(0, -1), base];
|
|
557
|
+
return {
|
|
558
|
+
key: one.key,
|
|
559
|
+
from: one.from.key,
|
|
560
|
+
to: one.to.key,
|
|
561
|
+
edges: one.edges,
|
|
562
|
+
points,
|
|
563
|
+
d: pathOf(drawn),
|
|
564
|
+
arrow: `M${n(endX)} ${n(one.toY)}L${n(base.x)} ${n(one.toY - ARROW_HALF)}L${n(base.x)} ${n(one.toY + ARROW_HALF)}Z`,
|
|
565
|
+
box: boxOf(points)
|
|
566
|
+
};
|
|
567
|
+
});
|
|
568
|
+
return { routes, routeOfEdge };
|
|
569
|
+
}
|
|
570
|
+
var TRUNK_INSET = 48;
|
|
571
|
+
function graphTrunks(layout, edges, laneOf) {
|
|
572
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
573
|
+
for (const edge of edges) {
|
|
574
|
+
const a = layout.laneById.get(laneOf(edge.from) ?? "");
|
|
575
|
+
const b = layout.laneById.get(laneOf(edge.to) ?? "");
|
|
576
|
+
if (!a || !b || Math.abs(a.band - b.band) !== 1) continue;
|
|
577
|
+
const [upper, lower] = a.band < b.band ? [a, b] : [b, a];
|
|
578
|
+
const key = `${upper.id}>${lower.id}`;
|
|
579
|
+
const pair = pairs.get(key);
|
|
580
|
+
if (pair) pair.count += 1;
|
|
581
|
+
else pairs.set(key, { upper, lower, count: 1 });
|
|
582
|
+
}
|
|
583
|
+
return [...pairs].map(([key, { upper, lower, count }]) => {
|
|
584
|
+
const from = upper.panel;
|
|
585
|
+
const to = lower.panel;
|
|
586
|
+
const inset = Math.min(TRUNK_INSET, from.width / 4, to.width / 4);
|
|
587
|
+
const lo = Math.max(from.x, to.x) + inset;
|
|
588
|
+
const hi = Math.min(from.x + from.width, to.x + to.width) - inset;
|
|
589
|
+
const mid = from.x + from.width / 2;
|
|
590
|
+
const left = to.x + to.width / 2 < mid;
|
|
591
|
+
const x1 = lo <= hi ? Math.min(hi, Math.max(lo, mid)) : left ? from.x + inset : from.x + from.width - inset;
|
|
592
|
+
const x2 = lo <= hi ? x1 : left ? to.x + to.width - inset : to.x + inset;
|
|
593
|
+
const y1 = from.y + from.height;
|
|
594
|
+
const y2 = to.y;
|
|
595
|
+
const turn = (y1 + y2) / 2;
|
|
596
|
+
const points = simplify([
|
|
597
|
+
{ x: x1, y: y1 },
|
|
598
|
+
{ x: x1, y: turn },
|
|
599
|
+
{ x: x2, y: turn },
|
|
600
|
+
{ x: x2, y: y2 }
|
|
601
|
+
]);
|
|
602
|
+
return {
|
|
603
|
+
key,
|
|
604
|
+
from: upper.id,
|
|
605
|
+
to: lower.id,
|
|
606
|
+
count,
|
|
607
|
+
d: pathOf(points),
|
|
608
|
+
label: { x: (x1 + x2) / 2, y: turn },
|
|
609
|
+
box: boxOf(points)
|
|
610
|
+
};
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function plan(key, from, to, edge, grid, columns, metrics) {
|
|
614
|
+
const forward = to.col > from.col;
|
|
615
|
+
const back = to.col < from.col;
|
|
616
|
+
const exit = back ? "left" : "right";
|
|
617
|
+
const entry = forward ? "left" : "right";
|
|
618
|
+
const out = forward ? from.col + 1 : back ? from.col : from.col + 1;
|
|
619
|
+
const into = forward ? to.col : back ? to.col + 1 : to.col + 1;
|
|
620
|
+
const fromY = from.y + from.height / 2;
|
|
621
|
+
const toY = to.y + to.height / 2;
|
|
622
|
+
const base = {
|
|
623
|
+
key,
|
|
624
|
+
from,
|
|
625
|
+
to,
|
|
626
|
+
edges: [edge],
|
|
627
|
+
exit,
|
|
628
|
+
entry,
|
|
629
|
+
out,
|
|
630
|
+
in: into,
|
|
631
|
+
street: null,
|
|
632
|
+
straight: false,
|
|
633
|
+
fromY,
|
|
634
|
+
toY,
|
|
635
|
+
outX: grid.channelX[out],
|
|
636
|
+
inX: grid.channelX[into],
|
|
637
|
+
streetY: 0
|
|
638
|
+
};
|
|
639
|
+
if (out === into && from.band === to.band) return base;
|
|
640
|
+
if (from.band === to.band && from.row === to.row) {
|
|
641
|
+
const lo2 = Math.min(from.col, to.col) + 1;
|
|
642
|
+
const hi2 = Math.max(from.col, to.col) - 1;
|
|
643
|
+
const cells = grid.occupied[from.band];
|
|
644
|
+
let free = true;
|
|
645
|
+
for (let c = lo2; c <= hi2 && free; c++) if (cells[from.row * columns + c]) free = false;
|
|
646
|
+
if (free) return { ...base, straight: true };
|
|
647
|
+
}
|
|
648
|
+
const lo = Math.min(fromY, toY);
|
|
649
|
+
const hi = Math.max(fromY, toY);
|
|
650
|
+
const crossed = [];
|
|
651
|
+
for (let c = Math.min(out, into); c < Math.max(out, into); c++) crossed.push(c);
|
|
652
|
+
const pitch = metrics.cardHeight + metrics.rowGap;
|
|
653
|
+
if (from.band !== to.band) {
|
|
654
|
+
const gap = grid.gapStreets.get(from.band < to.band ? from.band + 1 : from.band);
|
|
655
|
+
return { ...base, street: gap ?? null };
|
|
656
|
+
}
|
|
657
|
+
const cost = (i) => {
|
|
658
|
+
const street = grid.streets[i];
|
|
659
|
+
const between = street.y >= lo && street.y <= hi;
|
|
660
|
+
let penalty = between ? 0 : pitch * 4;
|
|
661
|
+
for (const c of crossed) {
|
|
662
|
+
if (street.blocked[c]) penalty += pitch * 50;
|
|
663
|
+
else if (street.dirty[c]) penalty += pitch * 2;
|
|
664
|
+
}
|
|
665
|
+
return Math.abs(street.y - toY) + penalty;
|
|
666
|
+
};
|
|
667
|
+
const list = grid.bandStreets[from.band];
|
|
668
|
+
let at = 0;
|
|
669
|
+
let top = list.length;
|
|
670
|
+
while (at < top) {
|
|
671
|
+
const mid = at + top >> 1;
|
|
672
|
+
if (grid.streets[list[mid]].y < toY) at = mid + 1;
|
|
673
|
+
else top = mid;
|
|
674
|
+
}
|
|
675
|
+
let best = -1;
|
|
676
|
+
let bestCost = Infinity;
|
|
677
|
+
for (let i = at; i < list.length && grid.streets[list[i]].y - toY < bestCost; i++) {
|
|
678
|
+
const value = cost(list[i]);
|
|
679
|
+
if (value < bestCost) {
|
|
680
|
+
bestCost = value;
|
|
681
|
+
best = list[i];
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
for (let i = at - 1; i >= 0 && toY - grid.streets[list[i]].y < bestCost; i--) {
|
|
685
|
+
const value = cost(list[i]);
|
|
686
|
+
if (value < bestCost) {
|
|
687
|
+
bestCost = value;
|
|
688
|
+
best = list[i];
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return { ...base, street: best < 0 ? null : best };
|
|
692
|
+
}
|
|
693
|
+
function assignTracks(runs, step, room) {
|
|
694
|
+
const order = runs.map((_, i) => i).sort(
|
|
695
|
+
(a, b) => runs[a].lo - runs[b].lo || runs[a].hi - runs[b].hi || byText(runs[a].plan.key, runs[b].plan.key)
|
|
696
|
+
);
|
|
697
|
+
const track = new Array(runs.length).fill(0);
|
|
698
|
+
const busy = new Heap((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
699
|
+
const free = new Heap((a, b) => a - b);
|
|
700
|
+
let tracks = 0;
|
|
701
|
+
for (const i of order) {
|
|
702
|
+
const run = runs[i];
|
|
703
|
+
while (busy.size > 0 && busy.peek()[0] < run.lo - 1) free.push(busy.pop()[1]);
|
|
704
|
+
const t = free.size > 0 ? free.pop() : tracks++;
|
|
705
|
+
busy.push([run.hi, t]);
|
|
706
|
+
track[i] = t;
|
|
707
|
+
}
|
|
708
|
+
const most = Math.max(1, Math.floor(room / step) + 1);
|
|
709
|
+
return track.map((t) => {
|
|
710
|
+
const slot = t % most;
|
|
711
|
+
const side = slot % 2 === 0 ? 1 : -1;
|
|
712
|
+
return side * Math.ceil(slot / 2) * step;
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
var Heap = class {
|
|
716
|
+
constructor(before) {
|
|
717
|
+
this.before = before;
|
|
718
|
+
}
|
|
719
|
+
before;
|
|
720
|
+
items = [];
|
|
721
|
+
get size() {
|
|
722
|
+
return this.items.length;
|
|
723
|
+
}
|
|
724
|
+
peek() {
|
|
725
|
+
return this.items[0];
|
|
726
|
+
}
|
|
727
|
+
push(item) {
|
|
728
|
+
const items = this.items;
|
|
729
|
+
items.push(item);
|
|
730
|
+
let at = items.length - 1;
|
|
731
|
+
while (at > 0) {
|
|
732
|
+
const parent = at - 1 >> 1;
|
|
733
|
+
if (this.before(items[at], items[parent]) >= 0) break;
|
|
734
|
+
[items[at], items[parent]] = [items[parent], items[at]];
|
|
735
|
+
at = parent;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
pop() {
|
|
739
|
+
const items = this.items;
|
|
740
|
+
const top = items[0];
|
|
741
|
+
const last = items.pop();
|
|
742
|
+
if (items.length > 0 && last !== void 0) {
|
|
743
|
+
items[0] = last;
|
|
744
|
+
let at = 0;
|
|
745
|
+
for (; ; ) {
|
|
746
|
+
const left = at * 2 + 1;
|
|
747
|
+
const right = left + 1;
|
|
748
|
+
let least = at;
|
|
749
|
+
if (left < items.length && this.before(items[left], items[least]) < 0) least = left;
|
|
750
|
+
if (right < items.length && this.before(items[right], items[least]) < 0) least = right;
|
|
751
|
+
if (least === at) break;
|
|
752
|
+
[items[at], items[least]] = [items[least], items[at]];
|
|
753
|
+
at = least;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return top;
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
function byText(a, b) {
|
|
760
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
761
|
+
}
|
|
762
|
+
function boxOf(points) {
|
|
763
|
+
let left = Infinity;
|
|
764
|
+
let top = Infinity;
|
|
765
|
+
let right = -Infinity;
|
|
766
|
+
let bottom = -Infinity;
|
|
767
|
+
for (const point of points) {
|
|
768
|
+
left = Math.min(left, point.x);
|
|
769
|
+
top = Math.min(top, point.y);
|
|
770
|
+
right = Math.max(right, point.x);
|
|
771
|
+
bottom = Math.max(bottom, point.y);
|
|
772
|
+
}
|
|
773
|
+
return { x: left, y: top - ARROW_HALF, width: right - left, height: bottom - top + 2 * ARROW_HALF };
|
|
774
|
+
}
|
|
775
|
+
function simplify(points) {
|
|
776
|
+
const out = [];
|
|
777
|
+
for (const point of points) {
|
|
778
|
+
const last = out[out.length - 1];
|
|
779
|
+
if (last && Math.abs(last.x - point.x) < 0.01 && Math.abs(last.y - point.y) < 0.01) continue;
|
|
780
|
+
const before = out[out.length - 2];
|
|
781
|
+
if (before && last) {
|
|
782
|
+
const inLine = Math.abs(before.x - last.x) < 0.01 && Math.abs(last.x - point.x) < 0.01 || Math.abs(before.y - last.y) < 0.01 && Math.abs(last.y - point.y) < 0.01;
|
|
783
|
+
if (inLine) out.pop();
|
|
784
|
+
}
|
|
785
|
+
out.push(point);
|
|
786
|
+
}
|
|
787
|
+
return out;
|
|
788
|
+
}
|
|
789
|
+
function pathOf(points) {
|
|
790
|
+
if (points.length === 0) return "";
|
|
791
|
+
let d = `M${n(points[0].x)} ${n(points[0].y)}`;
|
|
792
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
793
|
+
const a = points[i - 1];
|
|
794
|
+
const b = points[i];
|
|
795
|
+
const c = points[i + 1];
|
|
796
|
+
const r = Math.min(CORNER, distance(a, b) / 2, distance(b, c) / 2);
|
|
797
|
+
const inPoint = toward(b, a, r);
|
|
798
|
+
const outPoint = toward(b, c, r);
|
|
799
|
+
d += `L${n(inPoint.x)} ${n(inPoint.y)}Q${n(b.x)} ${n(b.y)} ${n(outPoint.x)} ${n(outPoint.y)}`;
|
|
800
|
+
}
|
|
801
|
+
const last = points[points.length - 1];
|
|
802
|
+
return `${d}L${n(last.x)} ${n(last.y)}`;
|
|
803
|
+
}
|
|
804
|
+
function distance(a, b) {
|
|
805
|
+
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
806
|
+
}
|
|
807
|
+
function toward(from, to, by) {
|
|
808
|
+
const length = distance(from, to);
|
|
809
|
+
if (length === 0) return from;
|
|
810
|
+
return { x: from.x + (to.x - from.x) * by / length, y: from.y + (to.y - from.y) * by / length };
|
|
811
|
+
}
|
|
812
|
+
function n(value) {
|
|
813
|
+
return String(Math.round(value * 10) / 10);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/GraphCanvas/reach.ts
|
|
817
|
+
function graphReach(edges, from, direction, depth) {
|
|
818
|
+
const out = /* @__PURE__ */ new Map();
|
|
819
|
+
const into = /* @__PURE__ */ new Map();
|
|
820
|
+
for (const edge of edges) {
|
|
821
|
+
if (edge.from === edge.to) continue;
|
|
822
|
+
let list = out.get(edge.from);
|
|
823
|
+
if (!list) out.set(edge.from, list = []);
|
|
824
|
+
list.push(edge);
|
|
825
|
+
list = into.get(edge.to);
|
|
826
|
+
if (!list) into.set(edge.to, list = []);
|
|
827
|
+
list.push(edge);
|
|
828
|
+
}
|
|
829
|
+
const nodes = /* @__PURE__ */ new Map([[from, 0]]);
|
|
830
|
+
const taken = /* @__PURE__ */ new Set();
|
|
831
|
+
const walk = (next, far) => {
|
|
832
|
+
const seen = /* @__PURE__ */ new Map([[from, 0]]);
|
|
833
|
+
let frontier = [from];
|
|
834
|
+
for (let hop = 1; hop <= depth && frontier.length > 0; hop++) {
|
|
835
|
+
const following = [];
|
|
836
|
+
for (const id of frontier) {
|
|
837
|
+
for (const edge of next(id) ?? []) {
|
|
838
|
+
const other = far(edge);
|
|
839
|
+
taken.add(edge.id);
|
|
840
|
+
if (seen.has(other)) continue;
|
|
841
|
+
seen.set(other, hop);
|
|
842
|
+
following.push(other);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
frontier = following;
|
|
846
|
+
}
|
|
847
|
+
for (const [id, hops] of seen) nodes.set(id, Math.min(hops, nodes.get(id) ?? Infinity));
|
|
848
|
+
};
|
|
849
|
+
if (direction === "up" || direction === "both")
|
|
850
|
+
walk(
|
|
851
|
+
(id) => into.get(id),
|
|
852
|
+
(edge) => edge.from
|
|
853
|
+
);
|
|
854
|
+
if (direction === "down" || direction === "both")
|
|
855
|
+
walk(
|
|
856
|
+
(id) => out.get(id),
|
|
857
|
+
(edge) => edge.to
|
|
858
|
+
);
|
|
859
|
+
return { nodes, edges: taken };
|
|
860
|
+
}
|
|
861
|
+
function graphNeighbourhood(edges, id) {
|
|
862
|
+
const nodes = /* @__PURE__ */ new Map([[id, 0]]);
|
|
863
|
+
const taken = /* @__PURE__ */ new Set();
|
|
864
|
+
for (const edge of edges) {
|
|
865
|
+
if (edge.from === edge.to) continue;
|
|
866
|
+
if (edge.from === id) {
|
|
867
|
+
nodes.set(edge.to, 1);
|
|
868
|
+
taken.add(edge.id);
|
|
869
|
+
} else if (edge.to === id) {
|
|
870
|
+
nodes.set(edge.from, 1);
|
|
871
|
+
taken.add(edge.id);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return { nodes, edges: taken };
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/GraphCanvas/walk.ts
|
|
878
|
+
function graphStep(layout, from, event) {
|
|
879
|
+
const item = layout.itemByKey.get(from);
|
|
880
|
+
if (!item) return void 0;
|
|
881
|
+
const lane = layout.laneById.get(item.lane);
|
|
882
|
+
const mod = event.ctrlKey === true || event.metaKey === true;
|
|
883
|
+
switch (event.key) {
|
|
884
|
+
case "ArrowDown":
|
|
885
|
+
return alongColumn(layout, item, lane, 1) ?? acrossBands(layout, item, 1);
|
|
886
|
+
case "ArrowUp":
|
|
887
|
+
return alongColumn(layout, item, lane, -1) ?? acrossBands(layout, item, -1);
|
|
888
|
+
case "ArrowRight":
|
|
889
|
+
return besideColumn(layout, item, lane, 1) ?? besideLane(layout, item, lane, 1);
|
|
890
|
+
case "ArrowLeft":
|
|
891
|
+
return besideColumn(layout, item, lane, -1) ?? besideLane(layout, item, lane, -1);
|
|
892
|
+
case "Home":
|
|
893
|
+
return mod ? layout.lanes[0]?.items[0] ?? null : lane.items[0];
|
|
894
|
+
case "End": {
|
|
895
|
+
if (!mod) return lane.items[lane.items.length - 1];
|
|
896
|
+
const last = layout.lanes[layout.lanes.length - 1];
|
|
897
|
+
return last ? last.items[last.items.length - 1] : null;
|
|
898
|
+
}
|
|
899
|
+
default:
|
|
900
|
+
return void 0;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
var middle = (item) => item.y + item.height / 2;
|
|
904
|
+
var centre = (item) => item.x + item.width / 2;
|
|
905
|
+
var covers = (item, col) => col >= item.col && col < item.col + item.cols;
|
|
906
|
+
function alongColumn(layout, item, lane, step) {
|
|
907
|
+
let best = null;
|
|
908
|
+
let bestRow = Infinity;
|
|
909
|
+
for (const key of lane.items) {
|
|
910
|
+
const other = layout.itemByKey.get(key);
|
|
911
|
+
const away = (other.row - item.row) * step;
|
|
912
|
+
if (other === item || away <= 0 || away >= bestRow) continue;
|
|
913
|
+
let shares = false;
|
|
914
|
+
for (let col = item.col; col < item.col + item.cols && !shares; col++) shares = covers(other, col);
|
|
915
|
+
if (!shares) continue;
|
|
916
|
+
best = key;
|
|
917
|
+
bestRow = away;
|
|
918
|
+
}
|
|
919
|
+
return best;
|
|
920
|
+
}
|
|
921
|
+
function besideColumn(layout, item, lane, step) {
|
|
922
|
+
const edge = step === 1 ? item.col + item.cols - 1 : item.col;
|
|
923
|
+
let best = null;
|
|
924
|
+
let bestCost = Infinity;
|
|
925
|
+
for (const key of lane.items) {
|
|
926
|
+
const other = layout.itemByKey.get(key);
|
|
927
|
+
const away = step === 1 ? other.col - edge : edge - (other.col + other.cols - 1);
|
|
928
|
+
if (other === item || away <= 0) continue;
|
|
929
|
+
const cost = away * 1e6 + Math.abs(middle(other) - middle(item));
|
|
930
|
+
if (cost < bestCost) {
|
|
931
|
+
bestCost = cost;
|
|
932
|
+
best = key;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return best;
|
|
936
|
+
}
|
|
937
|
+
function besideLane(layout, item, lane, step) {
|
|
938
|
+
const inBand = layout.lanes.filter((one) => one.band === lane.band);
|
|
939
|
+
const next = inBand[inBand.indexOf(lane) + step];
|
|
940
|
+
if (!next) return null;
|
|
941
|
+
return nearest(layout, next.items, (other) => Math.abs(middle(other) - middle(item)));
|
|
942
|
+
}
|
|
943
|
+
function acrossBands(layout, item, step) {
|
|
944
|
+
const band = item.band + step;
|
|
945
|
+
const lanes = layout.lanes.filter((one) => one.band === band);
|
|
946
|
+
if (lanes.length === 0) return null;
|
|
947
|
+
const x = centre(item);
|
|
948
|
+
let best = null;
|
|
949
|
+
let bestDistance = Infinity;
|
|
950
|
+
for (const lane of lanes) {
|
|
951
|
+
const left = lane.panel.x;
|
|
952
|
+
const right = lane.panel.x + lane.panel.width;
|
|
953
|
+
const distance2 = x < left ? left - x : x > right ? x - right : 0;
|
|
954
|
+
if (distance2 < bestDistance) {
|
|
955
|
+
bestDistance = distance2;
|
|
956
|
+
best = lane;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
if (!best) return null;
|
|
960
|
+
return nearest(layout, best.items, (other) => other.row * step * 1e6 + Math.abs(centre(other) - x));
|
|
961
|
+
}
|
|
962
|
+
function nearest(layout, keys, cost) {
|
|
963
|
+
let best = null;
|
|
964
|
+
let bestCost = Infinity;
|
|
965
|
+
for (const key of keys) {
|
|
966
|
+
const value = cost(layout.itemByKey.get(key));
|
|
967
|
+
if (value < bestCost) {
|
|
968
|
+
bestCost = value;
|
|
969
|
+
best = key;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return best;
|
|
973
|
+
}
|
|
974
|
+
var GRAPH_EDGE_FAMILIES = ["flow", "support", "context"];
|
|
975
|
+
var plural = (count, one, many) => `${count} ${count === 1 ? one : many}`;
|
|
976
|
+
var relationWords = (list) => list.map((one) => `${one.relation ?? "depends on"} ${one.name}`).join(", ");
|
|
977
|
+
var GRAPH_CANVAS_LABELS = {
|
|
978
|
+
zoomIn: "Zoom in",
|
|
979
|
+
zoomOut: "Zoom out",
|
|
980
|
+
fit: "Fit to view",
|
|
981
|
+
actualSize: "Zoom to 100%",
|
|
982
|
+
zoom: (percent) => `Zoom is ${percent} percent. Set a zoom level`,
|
|
983
|
+
zoomLevel: "Zoom level, percent",
|
|
984
|
+
done: "Done",
|
|
985
|
+
keys: "Arrow keys move between items and lanes, Enter selects an item or opens a group, and Escape clears the selection. Plus and minus zoom, and zero fits the map in view.",
|
|
986
|
+
lane: (label, count) => `${label}, ${plural(count, "item", "items")}`,
|
|
987
|
+
entries: (count) => plural(count, "item", "items"),
|
|
988
|
+
openGroup: (label, count) => `${label}, ${plural(count, "item", "items")}, open`,
|
|
989
|
+
closedGroup: (label, count) => `${label}, ${plural(count, "item", "items")}, closed`,
|
|
990
|
+
emptyLane: (label) => `${label}, empty`,
|
|
991
|
+
unconfirmed: "Unconfirmed",
|
|
992
|
+
relations: (dependsOn, usedBy) => {
|
|
993
|
+
const parts = [];
|
|
994
|
+
if (dependsOn.length > 0) parts.push(`${relationWords(dependsOn)}.`);
|
|
995
|
+
if (usedBy.length > 0) parts.push(`Used by ${usedBy.map((one) => one.name).join(", ")}.`);
|
|
996
|
+
return parts.join(" ");
|
|
997
|
+
},
|
|
998
|
+
legend: "Legend",
|
|
999
|
+
families: { flow: "Calls", support: "Runs on", context: "Around it" },
|
|
1000
|
+
quiet: "Quiet",
|
|
1001
|
+
trunk: (lines) => `${lines} run on`,
|
|
1002
|
+
fullscreen: "Fullscreen",
|
|
1003
|
+
leaveFullscreen: "Leave fullscreen"
|
|
1004
|
+
};
|
|
1005
|
+
var GRAPH_CANVAS_DETAIL_ZOOM = 0.5;
|
|
1006
|
+
var GRAPH_CANVAS_OPEN_ZOOM = 0.75;
|
|
1007
|
+
var GRAPH_CANVAS_FIT_FLOOR = 0.02;
|
|
1008
|
+
var GRAPH_CANVAS_FLOW_LIMIT = 160;
|
|
1009
|
+
var POINT_IN_MS = 90;
|
|
1010
|
+
var POINT_OUT_MS = 120;
|
|
1011
|
+
var PRESS_SLOP = 4;
|
|
1012
|
+
var GRAPH_CANVAS_NARROW_WIDTH = 800;
|
|
1013
|
+
var CARD_GAP = 12;
|
|
1014
|
+
var CARD_INSET = 8;
|
|
1015
|
+
var CARD_PROBE = "crewlet:graph-canvas-card";
|
|
1016
|
+
var GAP_PROBE = "crewlet:graph-canvas-gap";
|
|
1017
|
+
var PAD_PROBE = "crewlet:graph-canvas-pad";
|
|
1018
|
+
var HEAD_PROBE = "crewlet:graph-canvas-head";
|
|
1019
|
+
var BAND_PROBE = "crewlet:graph-canvas-band";
|
|
1020
|
+
var PROBES = [CARD_PROBE, GAP_PROBE, PAD_PROBE, HEAD_PROBE, BAND_PROBE];
|
|
1021
|
+
var emptyProbe = (lane) => `crewlet:graph-canvas-empty:${lane}`;
|
|
1022
|
+
var NO_GROUPS = [];
|
|
1023
|
+
var AT_REST = /* @__PURE__ */ new Set(["flow"]);
|
|
1024
|
+
var FAMILY_RANK = { context: 0, support: 1, flow: 2 };
|
|
1025
|
+
var TONES = ["danger", "warning", "info"];
|
|
1026
|
+
var EDGE_STATES = ["dim", "rest", "lit"];
|
|
1027
|
+
var DRAW_ORDER = ["context", "support", "flow"];
|
|
1028
|
+
var TONE_RANK = { info: 1, warning: 2, danger: 3 };
|
|
1029
|
+
function GraphCanvas({
|
|
1030
|
+
label,
|
|
1031
|
+
bands,
|
|
1032
|
+
nodes,
|
|
1033
|
+
edges,
|
|
1034
|
+
groups = NO_GROUPS,
|
|
1035
|
+
collapseAbove,
|
|
1036
|
+
openGroups,
|
|
1037
|
+
onOpenGroupsChange,
|
|
1038
|
+
selectedId = null,
|
|
1039
|
+
onSelect,
|
|
1040
|
+
trace = null,
|
|
1041
|
+
hoveredId = null,
|
|
1042
|
+
onHover,
|
|
1043
|
+
renderCard,
|
|
1044
|
+
dock,
|
|
1045
|
+
families,
|
|
1046
|
+
onFamiliesChange,
|
|
1047
|
+
tones,
|
|
1048
|
+
chrome = true,
|
|
1049
|
+
fullscreen = true,
|
|
1050
|
+
cardDimmed,
|
|
1051
|
+
overlay,
|
|
1052
|
+
controlsPlacement,
|
|
1053
|
+
controlsExtra,
|
|
1054
|
+
controlsBelow,
|
|
1055
|
+
controlsStart,
|
|
1056
|
+
overlayEnd,
|
|
1057
|
+
hint,
|
|
1058
|
+
ground,
|
|
1059
|
+
labels,
|
|
1060
|
+
minZoom = GRAPH_CANVAS_FIT_FLOOR,
|
|
1061
|
+
fitKey,
|
|
1062
|
+
initialView,
|
|
1063
|
+
onViewChange,
|
|
1064
|
+
ref,
|
|
1065
|
+
className
|
|
1066
|
+
}) {
|
|
1067
|
+
const text = useMemo(() => ({ ...GRAPH_CANVAS_LABELS, ...labels }), [labels]);
|
|
1068
|
+
const uid = useId();
|
|
1069
|
+
const nodeById = useMemo(() => new Map(nodes.map((node) => [node.id, node])), [nodes]);
|
|
1070
|
+
const groupById = useMemo(() => new Map(groups.map((group) => [group.id, group])), [groups]);
|
|
1071
|
+
const familyOf = useMemo(() => new Map(edges.map((edge) => [edge.id, edge.family ?? "flow"])), [edges]);
|
|
1072
|
+
const [ownFamilies, setOwnFamilies] = useState(AT_REST);
|
|
1073
|
+
const shown = families ?? ownFamilies;
|
|
1074
|
+
const toggleFamily = useCallback(
|
|
1075
|
+
(family) => {
|
|
1076
|
+
const next = new Set(shown);
|
|
1077
|
+
if (next.has(family)) next.delete(family);
|
|
1078
|
+
else next.add(family);
|
|
1079
|
+
if (!families) setOwnFamilies(next);
|
|
1080
|
+
onFamiliesChange?.(next);
|
|
1081
|
+
},
|
|
1082
|
+
[shown, families, onFamiliesChange]
|
|
1083
|
+
);
|
|
1084
|
+
const restEdges = useMemo(() => edges.filter((edge) => shown.has(edge.family ?? "flow")), [edges, shown]);
|
|
1085
|
+
const carrying = useMemo(() => edges.filter((edge) => (edge.family ?? "flow") !== "context"), [edges]);
|
|
1086
|
+
const groupOf = useCallback((id) => nodeById.get(id)?.group, [nodeById]);
|
|
1087
|
+
const [toggled, setToggled] = useState(() => /* @__PURE__ */ new Map());
|
|
1088
|
+
const startClosed = collapseAbove !== void 0 && nodes.length > collapseAbove;
|
|
1089
|
+
const openSet = useMemo(() => {
|
|
1090
|
+
if (openGroups) return openGroups;
|
|
1091
|
+
const out = /* @__PURE__ */ new Set();
|
|
1092
|
+
for (const group of groups) if (toggled.get(group.id) ?? !startClosed) out.add(group.id);
|
|
1093
|
+
return out;
|
|
1094
|
+
}, [openGroups, groups, toggled, startClosed]);
|
|
1095
|
+
const setGroupOpen = useCallback(
|
|
1096
|
+
(id, open) => {
|
|
1097
|
+
if (openSet.has(id) === open) return;
|
|
1098
|
+
const next = new Set(openSet);
|
|
1099
|
+
if (open) next.add(id);
|
|
1100
|
+
else next.delete(id);
|
|
1101
|
+
if (!openGroups) setToggled((was) => new Map(was).set(id, open));
|
|
1102
|
+
onOpenGroupsChange?.(next);
|
|
1103
|
+
},
|
|
1104
|
+
[openSet, openGroups, onOpenGroupsChange]
|
|
1105
|
+
);
|
|
1106
|
+
const { measure, sizes, measured } = useMeasuredSizes();
|
|
1107
|
+
const metrics = useMemo(() => {
|
|
1108
|
+
if (!measured(PROBES)) return null;
|
|
1109
|
+
const card2 = sizes.get(CARD_PROBE);
|
|
1110
|
+
const gap = sizes.get(GAP_PROBE);
|
|
1111
|
+
const pad = sizes.get(PAD_PROBE);
|
|
1112
|
+
return {
|
|
1113
|
+
cardWidth: card2.width,
|
|
1114
|
+
cardHeight: card2.height,
|
|
1115
|
+
gutter: gap.width,
|
|
1116
|
+
rowGap: gap.height,
|
|
1117
|
+
laneHead: sizes.get(HEAD_PROBE).height,
|
|
1118
|
+
bandHead: sizes.get(BAND_PROBE).height,
|
|
1119
|
+
bandGap: pad.height,
|
|
1120
|
+
lanePad: pad.width,
|
|
1121
|
+
margin: pad.height
|
|
1122
|
+
};
|
|
1123
|
+
}, [measured, sizes]);
|
|
1124
|
+
const emptyLanes = useMemo(() => {
|
|
1125
|
+
const filled = new Set(nodes.map((node) => node.lane));
|
|
1126
|
+
return bands.flatMap((band) => band.lanes.filter((lane) => !filled.has(lane.id)));
|
|
1127
|
+
}, [bands, nodes]);
|
|
1128
|
+
const emptyHeights = useMemo(() => {
|
|
1129
|
+
const out = /* @__PURE__ */ new Map();
|
|
1130
|
+
for (const lane of emptyLanes) {
|
|
1131
|
+
const size = sizes.get(emptyProbe(lane.id));
|
|
1132
|
+
if (size) out.set(lane.id, size.height);
|
|
1133
|
+
}
|
|
1134
|
+
return out;
|
|
1135
|
+
}, [emptyLanes, sizes]);
|
|
1136
|
+
const layoutBands = useMemo(
|
|
1137
|
+
() => bands.map((band) => ({ id: band.id, titled: Boolean(band.label), lanes: band.lanes.map((lane) => lane.id) })),
|
|
1138
|
+
[bands]
|
|
1139
|
+
);
|
|
1140
|
+
const laneColumns = useMemo(() => {
|
|
1141
|
+
const out = /* @__PURE__ */ new Map();
|
|
1142
|
+
for (const band of bands) for (const lane of band.lanes) if (lane.columns !== void 0) out.set(lane.id, lane.columns);
|
|
1143
|
+
return out;
|
|
1144
|
+
}, [bands]);
|
|
1145
|
+
const layout = useMemo(() => {
|
|
1146
|
+
if (!metrics) return null;
|
|
1147
|
+
return layoutGraph(
|
|
1148
|
+
{
|
|
1149
|
+
bands: layoutBands,
|
|
1150
|
+
nodes,
|
|
1151
|
+
groups,
|
|
1152
|
+
open: (id) => openSet.has(id),
|
|
1153
|
+
edges: restEdges,
|
|
1154
|
+
ordering: carrying,
|
|
1155
|
+
laneColumns,
|
|
1156
|
+
emptyHeights
|
|
1157
|
+
},
|
|
1158
|
+
metrics
|
|
1159
|
+
);
|
|
1160
|
+
}, [metrics, layoutBands, nodes, groups, openSet, restEdges, carrying, laneColumns, emptyHeights]);
|
|
1161
|
+
const everPlaced = useRef(false);
|
|
1162
|
+
const placed = layout !== null && (everPlaced.current || measured(emptyLanes.map((lane) => emptyProbe(lane.id))));
|
|
1163
|
+
if (placed) everPlaced.current = true;
|
|
1164
|
+
const laneOf = useMemo(() => new Map(bands.flatMap((band) => band.lanes.map((lane) => [lane.id, lane]))), [bands]);
|
|
1165
|
+
const [own, setOwn] = useState(null);
|
|
1166
|
+
const [card, setCard] = useState(null);
|
|
1167
|
+
const pointTimer = useRef(void 0);
|
|
1168
|
+
const hoverNow = useRef(onHover);
|
|
1169
|
+
hoverNow.current = onHover;
|
|
1170
|
+
const point = useCallback((id, delay) => {
|
|
1171
|
+
clearTimeout(pointTimer.current);
|
|
1172
|
+
const land = () => {
|
|
1173
|
+
setOwn(id);
|
|
1174
|
+
setCard(id);
|
|
1175
|
+
hoverNow.current?.(id);
|
|
1176
|
+
};
|
|
1177
|
+
if (delay === 0) land();
|
|
1178
|
+
else pointTimer.current = setTimeout(land, delay);
|
|
1179
|
+
}, []);
|
|
1180
|
+
useEffect(() => () => clearTimeout(pointTimer.current), []);
|
|
1181
|
+
const pointed = own ?? hoveredId;
|
|
1182
|
+
const reach = useMemo(() => {
|
|
1183
|
+
const focus = selectedId !== null && nodeById.has(selectedId) ? selectedId : null;
|
|
1184
|
+
const beside = pointed !== null && nodeById.has(pointed) ? pointed : null;
|
|
1185
|
+
if (focus === null) return beside === null ? null : graphNeighbourhood(edges, beside);
|
|
1186
|
+
const far = graphReach(carrying, focus, trace?.direction ?? "both", trace?.depth ?? Infinity);
|
|
1187
|
+
const near = graphNeighbourhood(edges, focus);
|
|
1188
|
+
const reached = new Map(far.nodes);
|
|
1189
|
+
for (const [id, hops] of near.nodes) if (!reached.has(id)) reached.set(id, hops);
|
|
1190
|
+
if (beside !== null && !reached.has(beside)) reached.set(beside, Infinity);
|
|
1191
|
+
return { nodes: reached, edges: /* @__PURE__ */ new Set([...far.edges, ...near.edges]) };
|
|
1192
|
+
}, [selectedId, pointed, nodeById, trace, edges, carrying]);
|
|
1193
|
+
const focusState = reach === null ? void 0 : selectedId !== null && nodeById.has(selectedId) ? "selected" : "hover";
|
|
1194
|
+
const nodeDimmed = useCallback(
|
|
1195
|
+
(id) => Boolean(cardDimmed?.(id)) || reach !== null && !reach.nodes.has(id),
|
|
1196
|
+
[cardDimmed, reach]
|
|
1197
|
+
);
|
|
1198
|
+
const selectedGroup = selectedId === null ? void 0 : groupOf(selectedId);
|
|
1199
|
+
const anchorNext = useRef(null);
|
|
1200
|
+
const openedFor = useRef(null);
|
|
1201
|
+
useLayoutEffect(() => {
|
|
1202
|
+
if (!layout || selectedId === openedFor.current) return;
|
|
1203
|
+
openedFor.current = selectedId;
|
|
1204
|
+
if (selectedId === null || selectedGroup === void 0 || openSet.has(selectedGroup)) return;
|
|
1205
|
+
const summary = layout.itemByKey.get(graphItemKey("summary", selectedGroup));
|
|
1206
|
+
if (summary) anchorNext.current = { key: graphItemKey("node", selectedId), before: summary };
|
|
1207
|
+
setGroupOpen(selectedGroup, true);
|
|
1208
|
+
}, [selectedGroup, selectedId, openSet, layout, setGroupOpen]);
|
|
1209
|
+
const drawn = useMemo(() => {
|
|
1210
|
+
if (!layout) return null;
|
|
1211
|
+
const strongest = (ids, only) => {
|
|
1212
|
+
let best = "context";
|
|
1213
|
+
for (const id of ids) {
|
|
1214
|
+
if (only && !only.has(id)) continue;
|
|
1215
|
+
const family = familyOf.get(id) ?? "flow";
|
|
1216
|
+
if (FAMILY_RANK[family] > FAMILY_RANK[best]) best = family;
|
|
1217
|
+
}
|
|
1218
|
+
return best;
|
|
1219
|
+
};
|
|
1220
|
+
const borrowed = /* @__PURE__ */ new Map();
|
|
1221
|
+
const extra = [];
|
|
1222
|
+
const known = new Set(layout.routes.map((route) => route.key));
|
|
1223
|
+
if (reach) {
|
|
1224
|
+
for (const edge of edges) {
|
|
1225
|
+
if (!reach.edges.has(edge.id) || layout.routeOfEdge.has(edge.id)) continue;
|
|
1226
|
+
const from = layout.itemOfNode.get(edge.from);
|
|
1227
|
+
const to = layout.itemOfNode.get(edge.to);
|
|
1228
|
+
if (from === void 0 || to === void 0 || from === to) continue;
|
|
1229
|
+
const key = `${from}>${to}`;
|
|
1230
|
+
if (!known.has(key)) extra.push(edge);
|
|
1231
|
+
else borrowed.set(key, [...borrowed.get(key) ?? [], edge.id]);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const itemDimmed = (key) => {
|
|
1235
|
+
const item = layout.itemByKey.get(key);
|
|
1236
|
+
if (item.kind === "node") return nodeDimmed(item.id);
|
|
1237
|
+
return layout.groupById.get(item.id)?.members.every(nodeDimmed) ?? false;
|
|
1238
|
+
};
|
|
1239
|
+
const layers = /* @__PURE__ */ new Map();
|
|
1240
|
+
const put = (family, state, route) => {
|
|
1241
|
+
const key = `${family}:${state}`;
|
|
1242
|
+
const list = layers.get(key);
|
|
1243
|
+
if (list) list.push(route);
|
|
1244
|
+
else layers.set(key, [route]);
|
|
1245
|
+
};
|
|
1246
|
+
for (const route of layout.routes) {
|
|
1247
|
+
const also = borrowed.get(route.key);
|
|
1248
|
+
const lit = reach !== null && (also !== void 0 || route.edges.some((id) => reach.edges.has(id)));
|
|
1249
|
+
if (lit) put(strongest(also ? [...route.edges, ...also] : route.edges, reach.edges), "lit", route);
|
|
1250
|
+
else if (reach || itemDimmed(route.from) || itemDimmed(route.to)) put(strongest(route.edges), "dim", route);
|
|
1251
|
+
else put(strongest(route.edges), "rest", route);
|
|
1252
|
+
}
|
|
1253
|
+
for (const route of routeGraphEdges(layout, extra)) put(strongest(route.edges), "lit", route);
|
|
1254
|
+
return { layers, itemDimmed };
|
|
1255
|
+
}, [layout, reach, edges, nodeDimmed, familyOf]);
|
|
1256
|
+
const laneOfNode = useCallback((id) => nodeById.get(id)?.lane, [nodeById]);
|
|
1257
|
+
const trunks = useMemo(() => {
|
|
1258
|
+
if (!layout || !chrome || shown.has("support")) return [];
|
|
1259
|
+
return graphTrunks(
|
|
1260
|
+
layout,
|
|
1261
|
+
edges.filter((edge) => edge.family === "support"),
|
|
1262
|
+
laneOfNode
|
|
1263
|
+
);
|
|
1264
|
+
}, [layout, chrome, shown, edges, laneOfNode]);
|
|
1265
|
+
const relationsOf = useMemo(() => {
|
|
1266
|
+
const out = /* @__PURE__ */ new Map();
|
|
1267
|
+
const entry = (id) => {
|
|
1268
|
+
let one = out.get(id);
|
|
1269
|
+
if (!one) out.set(id, one = { dependsOn: [], usedBy: [] });
|
|
1270
|
+
return one;
|
|
1271
|
+
};
|
|
1272
|
+
for (const edge of edges) {
|
|
1273
|
+
const from = nodeById.get(edge.from);
|
|
1274
|
+
const to = nodeById.get(edge.to);
|
|
1275
|
+
if (!from || !to || from === to) continue;
|
|
1276
|
+
entry(from.id).dependsOn.push({ relation: edge.label, name: to.name });
|
|
1277
|
+
entry(to.id).usedBy.push({ relation: edge.label, name: from.name });
|
|
1278
|
+
}
|
|
1279
|
+
return out;
|
|
1280
|
+
}, [edges, nodeById]);
|
|
1281
|
+
const canvas = useRef(null);
|
|
1282
|
+
const [mounted, setMounted] = useState(null);
|
|
1283
|
+
const mountedNow = useRef(mounted);
|
|
1284
|
+
mountedNow.current = mounted;
|
|
1285
|
+
const viewport = useRef(null);
|
|
1286
|
+
const placeCardNow = useRef(() => {
|
|
1287
|
+
});
|
|
1288
|
+
const viewChanged = useCallback(
|
|
1289
|
+
(view, size) => {
|
|
1290
|
+
onViewChange?.(view, size);
|
|
1291
|
+
viewport.current = size;
|
|
1292
|
+
placeCardNow.current();
|
|
1293
|
+
const next = graphWindow(mountedNow.current, view, size);
|
|
1294
|
+
if (next !== mountedNow.current) setMounted(next);
|
|
1295
|
+
},
|
|
1296
|
+
[onViewChange]
|
|
1297
|
+
);
|
|
1298
|
+
const paths = useMemo(() => {
|
|
1299
|
+
if (!drawn) return null;
|
|
1300
|
+
const near = (route) => !mounted || intersects(route.box, mounted.rect);
|
|
1301
|
+
const out = /* @__PURE__ */ new Map();
|
|
1302
|
+
for (const [key, list] of drawn.layers) {
|
|
1303
|
+
const kept = key.endsWith(":lit") ? list : list.filter(near);
|
|
1304
|
+
out.set(key, {
|
|
1305
|
+
d: kept.map((route) => route.d).join(""),
|
|
1306
|
+
arrow: kept.map((route) => route.arrow).join(""),
|
|
1307
|
+
count: kept.length
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
return out;
|
|
1311
|
+
}, [drawn, mounted]);
|
|
1312
|
+
const still = (paths?.get("flow:rest")?.count ?? 0) > GRAPH_CANVAS_FLOW_LIMIT;
|
|
1313
|
+
const cardEl = useRef(null);
|
|
1314
|
+
const cardItem = card === null || !renderCard || !layout ? void 0 : layout.itemByKey.get(graphItemKey("node", card));
|
|
1315
|
+
placeCardNow.current = () => {
|
|
1316
|
+
const el = cardEl.current;
|
|
1317
|
+
const size = viewport.current;
|
|
1318
|
+
if (!el || !cardItem || !size || !canvas.current) return;
|
|
1319
|
+
const at = canvas.current.screenRect(cardItem);
|
|
1320
|
+
const width2 = el.offsetWidth;
|
|
1321
|
+
const height2 = el.offsetHeight;
|
|
1322
|
+
const fitsAfter = at.x + at.width + CARD_GAP + width2 <= size.width - CARD_INSET;
|
|
1323
|
+
const left = fitsAfter ? at.x + at.width + CARD_GAP : Math.max(CARD_INSET, at.x - CARD_GAP - width2);
|
|
1324
|
+
const top = Math.max(CARD_INSET, Math.min(at.y - CARD_GAP, size.height - height2 - CARD_INSET));
|
|
1325
|
+
el.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
|
|
1326
|
+
};
|
|
1327
|
+
useLayoutEffect(() => placeCardNow.current());
|
|
1328
|
+
const root = useRef(null);
|
|
1329
|
+
const [frame, setFrame] = useState(null);
|
|
1330
|
+
const [narrow, setNarrow] = useState(false);
|
|
1331
|
+
useLayoutEffect(() => {
|
|
1332
|
+
const el = root.current;
|
|
1333
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
1334
|
+
const observer = new ResizeObserver((entries) => {
|
|
1335
|
+
const box = entries[entries.length - 1]?.contentRect;
|
|
1336
|
+
if (!box || box.width <= 0 || box.height <= 0) return;
|
|
1337
|
+
setFrame((was) => was ?? { width: box.width, height: box.height });
|
|
1338
|
+
setNarrow(box.width < GRAPH_CANVAS_NARROW_WIDTH);
|
|
1339
|
+
});
|
|
1340
|
+
observer.observe(el);
|
|
1341
|
+
return () => observer.disconnect();
|
|
1342
|
+
}, []);
|
|
1343
|
+
const [barsBottom, setBarsBottom] = useState(0);
|
|
1344
|
+
useLayoutEffect(() => {
|
|
1345
|
+
const el = root.current;
|
|
1346
|
+
if (!el || !frame) return;
|
|
1347
|
+
const top = el.getBoundingClientRect().top;
|
|
1348
|
+
let bottom = 0;
|
|
1349
|
+
for (const bar2 of el.querySelectorAll(".crewlet-canvas__controls")) {
|
|
1350
|
+
const rect = bar2.getBoundingClientRect();
|
|
1351
|
+
if (rect.height > 0 && rect.top - top < frame.height / 2) bottom = Math.max(bottom, rect.bottom - top);
|
|
1352
|
+
}
|
|
1353
|
+
setBarsBottom(bottom);
|
|
1354
|
+
}, [frame, controlsStart, controlsPlacement]);
|
|
1355
|
+
const opening = useMemo(() => {
|
|
1356
|
+
if (initialView) return initialView;
|
|
1357
|
+
if (!layout || !frame) return void 0;
|
|
1358
|
+
const fit = fitView(layout.bounds, frame, CANVAS_FIT_PADDING, minZoom);
|
|
1359
|
+
if (fit.k >= GRAPH_CANVAS_DETAIL_ZOOM) return void 0;
|
|
1360
|
+
const k = GRAPH_CANVAS_OPEN_ZOOM;
|
|
1361
|
+
const y = Math.max(CANVAS_FIT_PADDING, barsBottom + CANVAS_FIT_PADDING / 2);
|
|
1362
|
+
return { k, x: CANVAS_FIT_PADDING - layout.bounds.x * k, y: y - layout.bounds.y * k };
|
|
1363
|
+
}, [initialView, layout, frame, minZoom, barsBottom]);
|
|
1364
|
+
const [active, setActive] = useState(null);
|
|
1365
|
+
const selectedKey = selectedId === null || !layout ? null : layout.itemOfNode.get(selectedId) ?? null;
|
|
1366
|
+
const activeKey = active !== null && layout?.itemByKey.has(active) ? active : selectedKey ?? layout?.lanes.find((lane) => lane.items.length > 0)?.items[0] ?? null;
|
|
1367
|
+
const elements = useRef(/* @__PURE__ */ new Map());
|
|
1368
|
+
const refs = useRef(/* @__PURE__ */ new Map());
|
|
1369
|
+
const refFor = useCallback((key) => {
|
|
1370
|
+
let callback = refs.current.get(key);
|
|
1371
|
+
if (!callback) {
|
|
1372
|
+
callback = (el) => {
|
|
1373
|
+
if (el) elements.current.set(key, el);
|
|
1374
|
+
else if (elements.current.get(key)?.isConnected === false) elements.current.delete(key);
|
|
1375
|
+
};
|
|
1376
|
+
refs.current.set(key, callback);
|
|
1377
|
+
}
|
|
1378
|
+
return callback;
|
|
1379
|
+
}, []);
|
|
1380
|
+
const pendingFocus = useRef(null);
|
|
1381
|
+
const focusNow = useCallback(
|
|
1382
|
+
(key) => {
|
|
1383
|
+
const el = elements.current.get(key);
|
|
1384
|
+
const item = layout?.itemByKey.get(key);
|
|
1385
|
+
if (!el || !el.isConnected || !item) return false;
|
|
1386
|
+
el.focus({ preventScroll: true });
|
|
1387
|
+
canvas.current?.reveal(item);
|
|
1388
|
+
return true;
|
|
1389
|
+
},
|
|
1390
|
+
[layout]
|
|
1391
|
+
);
|
|
1392
|
+
const focusItem = useCallback((key) => {
|
|
1393
|
+
setActive(key);
|
|
1394
|
+
pendingFocus.current = key;
|
|
1395
|
+
}, []);
|
|
1396
|
+
useLayoutEffect(() => {
|
|
1397
|
+
const key = pendingFocus.current;
|
|
1398
|
+
if (key !== null && focusNow(key)) pendingFocus.current = null;
|
|
1399
|
+
});
|
|
1400
|
+
useLayoutEffect(() => {
|
|
1401
|
+
const pending = anchorNext.current;
|
|
1402
|
+
if (!pending || !layout) return;
|
|
1403
|
+
const after = layout.itemByKey.get(pending.key);
|
|
1404
|
+
if (!after) return;
|
|
1405
|
+
anchorNext.current = null;
|
|
1406
|
+
canvas.current?.anchor(pending.before, after);
|
|
1407
|
+
}, [layout]);
|
|
1408
|
+
const toggleGroup = useCallback(
|
|
1409
|
+
(id, focus) => {
|
|
1410
|
+
if (!layout) return;
|
|
1411
|
+
const open = openSet.has(id);
|
|
1412
|
+
const before = layout.itemByKey.get(graphItemKey(open ? "head" : "summary", id));
|
|
1413
|
+
const next = graphItemKey(open ? "summary" : "head", id);
|
|
1414
|
+
if (before) anchorNext.current = { key: next, before };
|
|
1415
|
+
setGroupOpen(id, !open);
|
|
1416
|
+
setActive(next);
|
|
1417
|
+
if (focus) pendingFocus.current = next;
|
|
1418
|
+
},
|
|
1419
|
+
[layout, openSet, setGroupOpen]
|
|
1420
|
+
);
|
|
1421
|
+
const layoutNow = useRef(layout);
|
|
1422
|
+
layoutNow.current = layout;
|
|
1423
|
+
const openNow = useRef({ openSet, groupOf, setGroupOpen });
|
|
1424
|
+
openNow.current = { openSet, groupOf, setGroupOpen };
|
|
1425
|
+
useImperativeHandle(
|
|
1426
|
+
ref,
|
|
1427
|
+
() => ({
|
|
1428
|
+
focusNode: (id) => {
|
|
1429
|
+
const { openSet: shown2, groupOf: owner, setGroupOpen: reveal } = openNow.current;
|
|
1430
|
+
const group = owner(id);
|
|
1431
|
+
if (group !== void 0 && !shown2.has(group)) reveal(group, true);
|
|
1432
|
+
focusItem(graphItemKey("node", id));
|
|
1433
|
+
},
|
|
1434
|
+
fit: () => canvas.current?.fit()
|
|
1435
|
+
}),
|
|
1436
|
+
[focusItem]
|
|
1437
|
+
);
|
|
1438
|
+
const fittedFor = useRef(fitKey);
|
|
1439
|
+
const placedOnce = useRef(false);
|
|
1440
|
+
useLayoutEffect(() => {
|
|
1441
|
+
if (!placed) return;
|
|
1442
|
+
if (!placedOnce.current) {
|
|
1443
|
+
placedOnce.current = true;
|
|
1444
|
+
fittedFor.current = fitKey;
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
if (fitKey === fittedFor.current) return;
|
|
1448
|
+
fittedFor.current = fitKey;
|
|
1449
|
+
canvas.current?.fit();
|
|
1450
|
+
}, [fitKey, placed]);
|
|
1451
|
+
const typed = useRef({ text: "", at: 0 });
|
|
1452
|
+
const activate = useCallback(
|
|
1453
|
+
(item, focus) => {
|
|
1454
|
+
if (item.kind === "node") {
|
|
1455
|
+
onSelect?.(item.id === selectedId ? null : item.id);
|
|
1456
|
+
setActive(item.key);
|
|
1457
|
+
if (focus) pendingFocus.current = item.key;
|
|
1458
|
+
} else if (item.kind === "head" || item.kind === "summary") {
|
|
1459
|
+
toggleGroup(item.id, focus);
|
|
1460
|
+
}
|
|
1461
|
+
},
|
|
1462
|
+
[onSelect, selectedId, toggleGroup]
|
|
1463
|
+
);
|
|
1464
|
+
const pressed = useRef(null);
|
|
1465
|
+
const onPointerDownCapture = (event) => {
|
|
1466
|
+
pressed.current = { x: event.clientX, y: event.clientY };
|
|
1467
|
+
};
|
|
1468
|
+
const onGroundClick = (event) => {
|
|
1469
|
+
const from = pressed.current;
|
|
1470
|
+
pressed.current = null;
|
|
1471
|
+
if (!chrome || selectedId === null || !from) return;
|
|
1472
|
+
if (Math.hypot(event.clientX - from.x, event.clientY - from.y) > PRESS_SLOP) return;
|
|
1473
|
+
if (event.target.closest("[data-graph-key], [data-graph-solid], .crewlet-canvas__controls")) return;
|
|
1474
|
+
onSelect?.(null);
|
|
1475
|
+
};
|
|
1476
|
+
function onKeyDown(event) {
|
|
1477
|
+
if (!layout) return;
|
|
1478
|
+
if (event.key === "Escape") {
|
|
1479
|
+
if (card !== null) setCard(null);
|
|
1480
|
+
if (selectedId === null) return;
|
|
1481
|
+
event.preventDefault();
|
|
1482
|
+
event.stopPropagation();
|
|
1483
|
+
onSelect?.(null);
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1486
|
+
if (event.target !== event.currentTarget) return;
|
|
1487
|
+
const key = event.currentTarget.getAttribute("data-graph-key");
|
|
1488
|
+
if (key === null) return;
|
|
1489
|
+
const item = layout.itemByKey.get(key);
|
|
1490
|
+
if (!item) return;
|
|
1491
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1492
|
+
event.preventDefault();
|
|
1493
|
+
activate(item, true);
|
|
1494
|
+
return;
|
|
1495
|
+
}
|
|
1496
|
+
const step = graphStep(layout, key, event);
|
|
1497
|
+
if (step !== void 0) {
|
|
1498
|
+
event.preventDefault();
|
|
1499
|
+
if (step !== null) focusItem(step);
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
const now = Date.now();
|
|
1503
|
+
if (isTypeAheadKey(event, typed.current, now)) {
|
|
1504
|
+
typed.current = typeAheadBuffer(typed.current, event.key, now);
|
|
1505
|
+
const found = typeAhead(layout, key, typed.current.text, (one) => nameOf(one));
|
|
1506
|
+
if (found !== null) {
|
|
1507
|
+
event.preventDefault();
|
|
1508
|
+
focusItem(found);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
const handlers = useRef({ onKeyDown, activate, setActive, layout });
|
|
1513
|
+
handlers.current = { onKeyDown, activate, setActive, layout };
|
|
1514
|
+
const onItemPoint = useCallback(
|
|
1515
|
+
(id, how) => point(id, how === "focus" ? 0 : id === null ? POINT_OUT_MS : POINT_IN_MS),
|
|
1516
|
+
[point]
|
|
1517
|
+
);
|
|
1518
|
+
const onItemKey = useCallback((event) => handlers.current.onKeyDown(event), []);
|
|
1519
|
+
const onItemPress = useCallback((key) => {
|
|
1520
|
+
const item = handlers.current.layout?.itemByKey.get(key);
|
|
1521
|
+
if (item) handlers.current.activate(item, true);
|
|
1522
|
+
}, []);
|
|
1523
|
+
const onItemFocus = useCallback((key) => handlers.current.setActive(key), []);
|
|
1524
|
+
const nameOf = (item) => {
|
|
1525
|
+
if (item.kind === "node") return nodeById.get(item.id)?.name ?? "";
|
|
1526
|
+
if (item.kind === "empty") return laneOf.get(item.id)?.label ?? "";
|
|
1527
|
+
return groupById.get(item.id)?.label ?? "";
|
|
1528
|
+
};
|
|
1529
|
+
const shownItems = useMemo(() => {
|
|
1530
|
+
if (!layout || !mounted) return [];
|
|
1531
|
+
const keep = /* @__PURE__ */ new Set();
|
|
1532
|
+
if (activeKey !== null) keep.add(activeKey);
|
|
1533
|
+
if (selectedKey !== null) keep.add(selectedKey);
|
|
1534
|
+
return layout.items.filter((item) => {
|
|
1535
|
+
if (keep.has(item.key)) return true;
|
|
1536
|
+
if (!mounted.detail && item.kind !== "empty" && item.kind !== "head") return false;
|
|
1537
|
+
return intersects(item, mounted.rect);
|
|
1538
|
+
});
|
|
1539
|
+
}, [layout, mounted, activeKey, selectedKey]);
|
|
1540
|
+
const shownByLane = useMemo(() => {
|
|
1541
|
+
const out = /* @__PURE__ */ new Map();
|
|
1542
|
+
for (const item of shownItems) {
|
|
1543
|
+
let list = out.get(item.lane);
|
|
1544
|
+
if (!list) out.set(item.lane, list = []);
|
|
1545
|
+
list.push(item);
|
|
1546
|
+
}
|
|
1547
|
+
return out;
|
|
1548
|
+
}, [shownItems]);
|
|
1549
|
+
const worstOf = useCallback(
|
|
1550
|
+
(members) => {
|
|
1551
|
+
let worst;
|
|
1552
|
+
for (const id of members) {
|
|
1553
|
+
const attention = nodeById.get(id)?.attention;
|
|
1554
|
+
if (attention && (!worst || TONE_RANK[attention.tone] > TONE_RANK[worst.tone])) worst = attention;
|
|
1555
|
+
}
|
|
1556
|
+
return worst;
|
|
1557
|
+
},
|
|
1558
|
+
[nodeById]
|
|
1559
|
+
);
|
|
1560
|
+
const renderItem = (item) => {
|
|
1561
|
+
const common = {
|
|
1562
|
+
itemKey: item.key,
|
|
1563
|
+
item,
|
|
1564
|
+
tabIndex: item.key === activeKey ? 0 : -1,
|
|
1565
|
+
refFor,
|
|
1566
|
+
onPress: onItemPress,
|
|
1567
|
+
onFocusItem: onItemFocus,
|
|
1568
|
+
onItemKey
|
|
1569
|
+
};
|
|
1570
|
+
if (item.kind === "node") {
|
|
1571
|
+
const node = nodeById.get(item.id);
|
|
1572
|
+
const relations = relationsOf.get(item.id);
|
|
1573
|
+
return /* @__PURE__ */ jsx(
|
|
1574
|
+
GraphCard,
|
|
1575
|
+
{
|
|
1576
|
+
...common,
|
|
1577
|
+
node,
|
|
1578
|
+
selected: item.id === selectedId,
|
|
1579
|
+
state: nodeDimmed(item.id) ? "dim" : reach?.nodes.has(item.id) ? "lit" : "rest",
|
|
1580
|
+
onPoint: onItemPoint,
|
|
1581
|
+
description: relations ? text.relations(relations.dependsOn, relations.usedBy) : "",
|
|
1582
|
+
descriptionId: `${uid}-d-${encodeURIComponent(item.key)}`,
|
|
1583
|
+
unconfirmedLabel: text.unconfirmed
|
|
1584
|
+
},
|
|
1585
|
+
item.key
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
if (item.kind === "summary" || item.kind === "head") {
|
|
1589
|
+
const group = groupById.get(item.id);
|
|
1590
|
+
const members = layout?.groupById.get(item.id)?.members ?? [];
|
|
1591
|
+
return /* @__PURE__ */ jsx(
|
|
1592
|
+
GraphGroupItem,
|
|
1593
|
+
{
|
|
1594
|
+
...common,
|
|
1595
|
+
label: group?.label ?? item.id,
|
|
1596
|
+
lead: group?.lead,
|
|
1597
|
+
count: members.length,
|
|
1598
|
+
attention: item.kind === "summary" ? worstOf(members) : void 0,
|
|
1599
|
+
dimmed: drawn?.itemDimmed(item.key) ?? false,
|
|
1600
|
+
selected: item.key === selectedKey,
|
|
1601
|
+
text
|
|
1602
|
+
},
|
|
1603
|
+
item.key
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
const lane = laneOf.get(item.id);
|
|
1607
|
+
return /* @__PURE__ */ jsx(GraphEmptyLane, { ...common, label: text.emptyLane(lane?.label ?? item.id), children: lane?.empty }, item.key);
|
|
1608
|
+
};
|
|
1609
|
+
const width = layout?.bounds.width ?? 0;
|
|
1610
|
+
const height = layout?.bounds.height ?? 0;
|
|
1611
|
+
const tallies = useMemo(() => {
|
|
1612
|
+
const out = /* @__PURE__ */ new Map();
|
|
1613
|
+
for (const node of nodes) {
|
|
1614
|
+
if (!node.attention) continue;
|
|
1615
|
+
let tally = out.get(node.lane);
|
|
1616
|
+
if (!tally) out.set(node.lane, tally = {});
|
|
1617
|
+
tally[node.attention.tone] = (tally[node.attention.tone] ?? 0) + 1;
|
|
1618
|
+
}
|
|
1619
|
+
return out;
|
|
1620
|
+
}, [nodes]);
|
|
1621
|
+
const laneName = (id, count) => {
|
|
1622
|
+
const tally = tallies.get(id);
|
|
1623
|
+
const words = TONES.flatMap((tone) => tally?.[tone] && tones?.[tone] ? [`${tally[tone]} ${tones[tone]}`] : []);
|
|
1624
|
+
return [text.lane(laneOf.get(id)?.label ?? id, count), ...words].join(", ");
|
|
1625
|
+
};
|
|
1626
|
+
const legend = chrome ? /* @__PURE__ */ jsxs("div", { className: "crewlet-graph-canvas__legend", role: "group", "aria-label": text.legend, children: [
|
|
1627
|
+
TONES.map(
|
|
1628
|
+
(tone) => tones?.[tone] ? /* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__key", children: [
|
|
1629
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__key-notch", "data-tone": tone, "aria-hidden": "true" }),
|
|
1630
|
+
tones[tone]
|
|
1631
|
+
] }, tone) : null
|
|
1632
|
+
),
|
|
1633
|
+
/* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__key", children: [
|
|
1634
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__key-notch", "aria-hidden": "true" }),
|
|
1635
|
+
text.quiet
|
|
1636
|
+
] }),
|
|
1637
|
+
/* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__key", children: [
|
|
1638
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__key-notch", "data-unconfirmed": "", "aria-hidden": "true" }),
|
|
1639
|
+
text.unconfirmed
|
|
1640
|
+
] }),
|
|
1641
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__legend-rule", "aria-hidden": "true" }),
|
|
1642
|
+
GRAPH_EDGE_FAMILIES.map((family) => /* @__PURE__ */ jsx(FilterChip, { pressed: shown.has(family), onPressedChange: () => toggleFamily(family), children: /* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__switch", children: [
|
|
1643
|
+
/* @__PURE__ */ jsx("svg", { className: "crewlet-graph-canvas__key-line", "data-family": family, viewBox: "0 0 22 8", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M1 4h20" }) }),
|
|
1644
|
+
text.families[family]
|
|
1645
|
+
] }) }, family))
|
|
1646
|
+
] }) : null;
|
|
1647
|
+
const ownFullscreen = fullscreen === true;
|
|
1648
|
+
const fullscreenTarget = typeof fullscreen === "object" ? fullscreen : root;
|
|
1649
|
+
const bar = chrome && fullscreen !== false ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1650
|
+
/* @__PURE__ */ jsx(
|
|
1651
|
+
FullscreenToggle,
|
|
1652
|
+
{
|
|
1653
|
+
target: fullscreenTarget,
|
|
1654
|
+
labels: { enter: text.fullscreen, leave: text.leaveFullscreen }
|
|
1655
|
+
}
|
|
1656
|
+
),
|
|
1657
|
+
controlsExtra
|
|
1658
|
+
] }) : controlsExtra;
|
|
1659
|
+
const over = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1660
|
+
cardItem && card !== null ? /* @__PURE__ */ jsx("div", { ref: cardEl, className: "crewlet-graph-canvas__popup", role: "tooltip", children: renderCard?.(card) }) : null,
|
|
1661
|
+
dock && !narrow ? /* @__PURE__ */ jsx("div", { className: "crewlet-graph-canvas__dock", "data-graph-solid": "", children: dock }) : null,
|
|
1662
|
+
overlay
|
|
1663
|
+
] });
|
|
1664
|
+
const end = narrow ? overlayEnd : legend || overlayEnd ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1665
|
+
legend,
|
|
1666
|
+
overlayEnd
|
|
1667
|
+
] }) : void 0;
|
|
1668
|
+
const foot = narrow && (dock || legend) ? /* @__PURE__ */ jsxs("div", { className: "crewlet-graph-canvas__foot", "data-graph-solid": "", children: [
|
|
1669
|
+
dock ? /* @__PURE__ */ jsx("div", { className: "crewlet-graph-canvas__dock", children: dock }) : null,
|
|
1670
|
+
legend
|
|
1671
|
+
] }) : null;
|
|
1672
|
+
const body = frame ? /* @__PURE__ */ jsxs(
|
|
1673
|
+
Canvas,
|
|
1674
|
+
{
|
|
1675
|
+
label,
|
|
1676
|
+
content: placed ? layout.bounds : null,
|
|
1677
|
+
ref: canvas,
|
|
1678
|
+
overlay: over,
|
|
1679
|
+
controls: chrome,
|
|
1680
|
+
controlsPlacement,
|
|
1681
|
+
controlsExtra: bar,
|
|
1682
|
+
controlsBelow,
|
|
1683
|
+
controlsStart,
|
|
1684
|
+
overlayEnd: end,
|
|
1685
|
+
hint,
|
|
1686
|
+
ground,
|
|
1687
|
+
largestItemWidth: metrics?.cardWidth,
|
|
1688
|
+
labels: text,
|
|
1689
|
+
minZoom,
|
|
1690
|
+
initialView: opening,
|
|
1691
|
+
onViewChange: viewChanged,
|
|
1692
|
+
children: [
|
|
1693
|
+
/* @__PURE__ */ jsx(Probes, { measure }),
|
|
1694
|
+
emptyLanes.map((lane) => {
|
|
1695
|
+
const placedLane = layout?.laneById.get(lane.id);
|
|
1696
|
+
return /* @__PURE__ */ jsx(
|
|
1697
|
+
"div",
|
|
1698
|
+
{
|
|
1699
|
+
ref: measure(emptyProbe(lane.id)),
|
|
1700
|
+
className: "crewlet-graph-canvas__empty-probe",
|
|
1701
|
+
"aria-hidden": "true",
|
|
1702
|
+
inert: true,
|
|
1703
|
+
style: placedLane ? { width: `${placedLane.head.width}px` } : void 0,
|
|
1704
|
+
children: lane.empty
|
|
1705
|
+
},
|
|
1706
|
+
lane.id
|
|
1707
|
+
);
|
|
1708
|
+
}),
|
|
1709
|
+
layout && placed ? /* @__PURE__ */ jsxs("div", { className: "crewlet-graph-canvas__world", style: { width: `${width}px`, height: `${height}px` }, children: [
|
|
1710
|
+
/* @__PURE__ */ jsxs("svg", { className: "crewlet-graph-canvas__ground", width, height, "aria-hidden": "true", children: [
|
|
1711
|
+
layout.lanes.map((lane) => /* @__PURE__ */ jsx(
|
|
1712
|
+
"rect",
|
|
1713
|
+
{
|
|
1714
|
+
className: "crewlet-graph-canvas__lane",
|
|
1715
|
+
x: lane.panel.x,
|
|
1716
|
+
y: lane.panel.y,
|
|
1717
|
+
width: lane.panel.width,
|
|
1718
|
+
height: lane.panel.height
|
|
1719
|
+
},
|
|
1720
|
+
lane.id
|
|
1721
|
+
)),
|
|
1722
|
+
layout.groups.map(
|
|
1723
|
+
(group) => group.box ? /* @__PURE__ */ jsx(
|
|
1724
|
+
"rect",
|
|
1725
|
+
{
|
|
1726
|
+
className: "crewlet-graph-canvas__group",
|
|
1727
|
+
x: group.box.x,
|
|
1728
|
+
y: group.box.y,
|
|
1729
|
+
width: group.box.width,
|
|
1730
|
+
height: group.box.height
|
|
1731
|
+
},
|
|
1732
|
+
group.id
|
|
1733
|
+
) : null
|
|
1734
|
+
)
|
|
1735
|
+
] }),
|
|
1736
|
+
layout.bands.map(
|
|
1737
|
+
(band) => band.title ? /* @__PURE__ */ jsx(
|
|
1738
|
+
"div",
|
|
1739
|
+
{
|
|
1740
|
+
className: "crewlet-graph-canvas__band-title",
|
|
1741
|
+
"aria-hidden": "true",
|
|
1742
|
+
style: placedStyle(band.title),
|
|
1743
|
+
children: bands[band.index].label
|
|
1744
|
+
},
|
|
1745
|
+
band.id
|
|
1746
|
+
) : null
|
|
1747
|
+
),
|
|
1748
|
+
paths ? /* @__PURE__ */ jsxs("svg", { className: "crewlet-graph-canvas__edges", width, height, "aria-hidden": "true", children: [
|
|
1749
|
+
trunks.length > 0 ? /* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__trunk", d: trunks.map((trunk) => trunk.d).join("") }) : null,
|
|
1750
|
+
EDGE_STATES.flatMap(
|
|
1751
|
+
(state) => DRAW_ORDER.map((family) => {
|
|
1752
|
+
const layer = paths.get(`${family}:${state}`);
|
|
1753
|
+
if (!layer || layer.d === "") return null;
|
|
1754
|
+
return /* @__PURE__ */ jsxs(
|
|
1755
|
+
"g",
|
|
1756
|
+
{
|
|
1757
|
+
className: "crewlet-graph-canvas__edge-layer",
|
|
1758
|
+
"data-family": family,
|
|
1759
|
+
"data-state": state,
|
|
1760
|
+
children: [
|
|
1761
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__edge", d: layer.d }),
|
|
1762
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__arrow", d: layer.arrow }),
|
|
1763
|
+
family === "flow" && state !== "dim" ? /* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__flow", d: layer.d }) : null
|
|
1764
|
+
]
|
|
1765
|
+
},
|
|
1766
|
+
`${family}:${state}`
|
|
1767
|
+
);
|
|
1768
|
+
})
|
|
1769
|
+
)
|
|
1770
|
+
] }) : null,
|
|
1771
|
+
trunks.map((trunk) => /* @__PURE__ */ jsx(
|
|
1772
|
+
"span",
|
|
1773
|
+
{
|
|
1774
|
+
className: "crewlet-graph-canvas__trunk-label",
|
|
1775
|
+
"aria-hidden": "true",
|
|
1776
|
+
style: { transform: `translate(${trunk.label.x}px, ${trunk.label.y}px) translate(-50%, -50%)` },
|
|
1777
|
+
children: text.trunk(trunk.count)
|
|
1778
|
+
},
|
|
1779
|
+
trunk.key
|
|
1780
|
+
)),
|
|
1781
|
+
layout.lanes.map((lane) => {
|
|
1782
|
+
const tally = tallies.get(lane.id);
|
|
1783
|
+
return /* @__PURE__ */ jsx(
|
|
1784
|
+
"div",
|
|
1785
|
+
{
|
|
1786
|
+
className: "crewlet-graph-canvas__lane-head",
|
|
1787
|
+
"aria-hidden": "true",
|
|
1788
|
+
style: placedStyle(lane.head),
|
|
1789
|
+
children: /* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__lane-title", children: [
|
|
1790
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-label", children: laneOf.get(lane.id)?.label }),
|
|
1791
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-count", children: lane.count }),
|
|
1792
|
+
TONES.map(
|
|
1793
|
+
(tone) => tally?.[tone] ? /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-tone", "data-tone": tone, children: tally[tone] }, tone) : null
|
|
1794
|
+
)
|
|
1795
|
+
] })
|
|
1796
|
+
},
|
|
1797
|
+
lane.id
|
|
1798
|
+
);
|
|
1799
|
+
}),
|
|
1800
|
+
mounted && !mounted.detail ? /* @__PURE__ */ jsx(
|
|
1801
|
+
Shapes,
|
|
1802
|
+
{
|
|
1803
|
+
layout,
|
|
1804
|
+
nodeById,
|
|
1805
|
+
dimmed: drawn?.itemDimmed,
|
|
1806
|
+
worstOf,
|
|
1807
|
+
selectedKey
|
|
1808
|
+
}
|
|
1809
|
+
) : null,
|
|
1810
|
+
/* @__PURE__ */ jsx("div", { className: "crewlet-graph-canvas__items", children: bands.map((band, b) => {
|
|
1811
|
+
const lanes = layout.lanes.filter((lane) => lane.band === b);
|
|
1812
|
+
const inner = lanes.map((lane) => /* @__PURE__ */ jsx("div", { role: "group", "aria-label": laneName(lane.id, lane.count), children: (shownByLane.get(lane.id) ?? []).map(renderItem) }, lane.id));
|
|
1813
|
+
return band.label ? /* @__PURE__ */ jsx("div", { role: "group", "aria-label": band.label, children: inner }, band.id) : /* @__PURE__ */ jsx("div", { role: "none", children: inner }, band.id);
|
|
1814
|
+
}) })
|
|
1815
|
+
] }) : null
|
|
1816
|
+
]
|
|
1817
|
+
}
|
|
1818
|
+
) : null;
|
|
1819
|
+
return (
|
|
1820
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events -- a press on the ground clears the selection, which Escape does from the keys
|
|
1821
|
+
/* @__PURE__ */ jsx(
|
|
1822
|
+
"div",
|
|
1823
|
+
{
|
|
1824
|
+
ref: root,
|
|
1825
|
+
className: cx("crewlet-graph-canvas", className),
|
|
1826
|
+
"data-narrow": narrow ? "" : void 0,
|
|
1827
|
+
"data-focus": focusState,
|
|
1828
|
+
"data-still": still ? "" : void 0,
|
|
1829
|
+
onPointerDownCapture,
|
|
1830
|
+
onClick: onGroundClick,
|
|
1831
|
+
children: ownFullscreen ? /* @__PURE__ */ jsxs(LayerHost, { children: [
|
|
1832
|
+
body,
|
|
1833
|
+
foot
|
|
1834
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1835
|
+
body,
|
|
1836
|
+
foot
|
|
1837
|
+
] })
|
|
1838
|
+
}
|
|
1839
|
+
)
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
function Probes({ measure }) {
|
|
1843
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1844
|
+
/* @__PURE__ */ jsx(
|
|
1845
|
+
"div",
|
|
1846
|
+
{
|
|
1847
|
+
ref: measure(CARD_PROBE),
|
|
1848
|
+
className: "crewlet-graph-canvas__card crewlet-graph-canvas__probe",
|
|
1849
|
+
"aria-hidden": "true"
|
|
1850
|
+
}
|
|
1851
|
+
),
|
|
1852
|
+
/* @__PURE__ */ jsx(
|
|
1853
|
+
"div",
|
|
1854
|
+
{
|
|
1855
|
+
ref: measure(GAP_PROBE),
|
|
1856
|
+
className: "crewlet-graph-canvas__gap crewlet-graph-canvas__probe",
|
|
1857
|
+
"aria-hidden": "true"
|
|
1858
|
+
}
|
|
1859
|
+
),
|
|
1860
|
+
/* @__PURE__ */ jsx(
|
|
1861
|
+
"div",
|
|
1862
|
+
{
|
|
1863
|
+
ref: measure(PAD_PROBE),
|
|
1864
|
+
className: "crewlet-graph-canvas__pad crewlet-graph-canvas__probe",
|
|
1865
|
+
"aria-hidden": "true"
|
|
1866
|
+
}
|
|
1867
|
+
),
|
|
1868
|
+
/* @__PURE__ */ jsx(
|
|
1869
|
+
"div",
|
|
1870
|
+
{
|
|
1871
|
+
ref: measure(HEAD_PROBE),
|
|
1872
|
+
className: "crewlet-graph-canvas__lane-head crewlet-graph-canvas__probe",
|
|
1873
|
+
"aria-hidden": "true",
|
|
1874
|
+
children: /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-label", children: "M" })
|
|
1875
|
+
}
|
|
1876
|
+
),
|
|
1877
|
+
/* @__PURE__ */ jsx(
|
|
1878
|
+
"div",
|
|
1879
|
+
{
|
|
1880
|
+
ref: measure(BAND_PROBE),
|
|
1881
|
+
className: "crewlet-graph-canvas__band-title crewlet-graph-canvas__probe",
|
|
1882
|
+
"aria-hidden": "true",
|
|
1883
|
+
children: "M"
|
|
1884
|
+
}
|
|
1885
|
+
)
|
|
1886
|
+
] });
|
|
1887
|
+
}
|
|
1888
|
+
function toneGlyph(tone) {
|
|
1889
|
+
if (tone === "danger") return /* @__PURE__ */ jsx(TriangleAlertGlyph, {});
|
|
1890
|
+
if (tone === "warning") return /* @__PURE__ */ jsx(CircleAlertGlyph, {});
|
|
1891
|
+
return /* @__PURE__ */ jsx(InfoGlyph, {});
|
|
1892
|
+
}
|
|
1893
|
+
var GraphCard = memo(function GraphCard2({
|
|
1894
|
+
itemKey,
|
|
1895
|
+
item,
|
|
1896
|
+
tabIndex,
|
|
1897
|
+
refFor,
|
|
1898
|
+
onPress,
|
|
1899
|
+
onFocusItem,
|
|
1900
|
+
onItemKey,
|
|
1901
|
+
node,
|
|
1902
|
+
selected,
|
|
1903
|
+
state,
|
|
1904
|
+
onPoint,
|
|
1905
|
+
description,
|
|
1906
|
+
descriptionId,
|
|
1907
|
+
unconfirmedLabel
|
|
1908
|
+
}) {
|
|
1909
|
+
const spoken = [
|
|
1910
|
+
node.title ?? node.name,
|
|
1911
|
+
node.kind,
|
|
1912
|
+
node.caption,
|
|
1913
|
+
node.attention?.label,
|
|
1914
|
+
node.unconfirmed ? unconfirmedLabel : void 0
|
|
1915
|
+
].filter((part) => part !== void 0 && part !== "").join(", ");
|
|
1916
|
+
return /* @__PURE__ */ jsxs(
|
|
1917
|
+
"div",
|
|
1918
|
+
{
|
|
1919
|
+
ref: refFor(itemKey),
|
|
1920
|
+
role: "button",
|
|
1921
|
+
tabIndex,
|
|
1922
|
+
title: node.title,
|
|
1923
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
1924
|
+
"aria-current": selected ? "true" : void 0,
|
|
1925
|
+
"data-graph-key": itemKey,
|
|
1926
|
+
"data-attention": node.attention?.tone,
|
|
1927
|
+
"data-unconfirmed": node.unconfirmed ? "" : void 0,
|
|
1928
|
+
"data-selected": selected ? "" : void 0,
|
|
1929
|
+
"data-state": state,
|
|
1930
|
+
className: "crewlet-graph-canvas__card",
|
|
1931
|
+
style: { transform: `translate(${item.x}px, ${item.y}px)` },
|
|
1932
|
+
onClick: () => onPress(itemKey),
|
|
1933
|
+
onFocus: () => {
|
|
1934
|
+
onFocusItem(itemKey);
|
|
1935
|
+
onPoint(node.id, "focus");
|
|
1936
|
+
},
|
|
1937
|
+
onBlur: () => onPoint(null, "focus"),
|
|
1938
|
+
onPointerEnter: () => onPoint(node.id, "pointer"),
|
|
1939
|
+
onPointerLeave: () => onPoint(null, "pointer"),
|
|
1940
|
+
onKeyDown: onItemKey,
|
|
1941
|
+
children: [
|
|
1942
|
+
/* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__cell", "aria-hidden": "true", children: [
|
|
1943
|
+
node.glyph,
|
|
1944
|
+
node.mark ? /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__mark", children: node.mark }) : null
|
|
1945
|
+
] }),
|
|
1946
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__name", "aria-hidden": "true", children: node.name }),
|
|
1947
|
+
node.attention ? /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__badge", "aria-hidden": "true", children: node.attention.glyph ?? toneGlyph(node.attention.tone) }) : null,
|
|
1948
|
+
/* @__PURE__ */ jsx(SpokenName, { spoken, description, descriptionId })
|
|
1949
|
+
]
|
|
1950
|
+
}
|
|
1951
|
+
);
|
|
1952
|
+
});
|
|
1953
|
+
var GraphGroupItem = memo(function GraphGroupItem2({
|
|
1954
|
+
itemKey,
|
|
1955
|
+
item,
|
|
1956
|
+
tabIndex,
|
|
1957
|
+
refFor,
|
|
1958
|
+
onPress,
|
|
1959
|
+
onFocusItem,
|
|
1960
|
+
onItemKey,
|
|
1961
|
+
label,
|
|
1962
|
+
lead,
|
|
1963
|
+
count,
|
|
1964
|
+
attention,
|
|
1965
|
+
dimmed,
|
|
1966
|
+
selected,
|
|
1967
|
+
text
|
|
1968
|
+
}) {
|
|
1969
|
+
const open = item.kind === "head";
|
|
1970
|
+
const spoken = [open ? text.openGroup(label, count) : text.closedGroup(label, count), attention?.label].filter(Boolean).join(", ");
|
|
1971
|
+
return /* @__PURE__ */ jsx(
|
|
1972
|
+
"div",
|
|
1973
|
+
{
|
|
1974
|
+
ref: refFor(itemKey),
|
|
1975
|
+
role: "button",
|
|
1976
|
+
tabIndex,
|
|
1977
|
+
"aria-expanded": open,
|
|
1978
|
+
"data-graph-key": itemKey,
|
|
1979
|
+
"aria-current": selected ? "true" : void 0,
|
|
1980
|
+
"data-attention": attention?.tone,
|
|
1981
|
+
"data-state": dimmed ? "dim" : "rest",
|
|
1982
|
+
"data-selected": selected ? "" : void 0,
|
|
1983
|
+
className: open ? "crewlet-graph-canvas__head" : "crewlet-graph-canvas__card crewlet-graph-canvas__card--group",
|
|
1984
|
+
style: {
|
|
1985
|
+
transform: `translate(${item.x}px, ${item.y}px)`,
|
|
1986
|
+
...open ? { width: `${item.width}px`, height: `${item.height}px` } : {}
|
|
1987
|
+
},
|
|
1988
|
+
onClick: () => onPress(itemKey),
|
|
1989
|
+
onFocus: () => onFocusItem(itemKey),
|
|
1990
|
+
onKeyDown: onItemKey,
|
|
1991
|
+
children: open ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1992
|
+
/* @__PURE__ */ jsx(ChevronDownGlyph, { size: "xs", "aria-hidden": "true", className: "crewlet-graph-canvas__chevron" }),
|
|
1993
|
+
lead ? /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lead", "aria-hidden": "true", children: lead }) : null,
|
|
1994
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__group-label", "aria-hidden": "true", children: label }),
|
|
1995
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__group-count", "aria-hidden": "true", children: count }),
|
|
1996
|
+
/* @__PURE__ */ jsx(SpokenName, { spoken })
|
|
1997
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1998
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__cell", "aria-hidden": "true", children: lead ?? /* @__PURE__ */ jsx(ChevronRightGlyph, { size: "sm" }) }),
|
|
1999
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__name", "aria-hidden": "true", children: label }),
|
|
2000
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__group-count", "aria-hidden": "true", children: count }),
|
|
2001
|
+
/* @__PURE__ */ jsx(ChevronRightGlyph, { size: "xs", "aria-hidden": "true", className: "crewlet-graph-canvas__chevron" }),
|
|
2002
|
+
attention ? /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__badge", "aria-hidden": "true", children: attention.glyph ?? toneGlyph(attention.tone) }) : null,
|
|
2003
|
+
/* @__PURE__ */ jsx(SpokenName, { spoken })
|
|
2004
|
+
] })
|
|
2005
|
+
}
|
|
2006
|
+
);
|
|
2007
|
+
});
|
|
2008
|
+
function SpokenName({
|
|
2009
|
+
spoken,
|
|
2010
|
+
description,
|
|
2011
|
+
descriptionId
|
|
2012
|
+
}) {
|
|
2013
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2014
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: spoken }),
|
|
2015
|
+
description ? /* @__PURE__ */ jsx("span", { id: descriptionId, hidden: true, children: description }) : null
|
|
2016
|
+
] });
|
|
2017
|
+
}
|
|
2018
|
+
function GraphEmptyLane({
|
|
2019
|
+
itemKey,
|
|
2020
|
+
item,
|
|
2021
|
+
tabIndex,
|
|
2022
|
+
refFor,
|
|
2023
|
+
onFocusItem,
|
|
2024
|
+
onItemKey,
|
|
2025
|
+
label,
|
|
2026
|
+
children
|
|
2027
|
+
}) {
|
|
2028
|
+
return (
|
|
2029
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- see above
|
|
2030
|
+
/* @__PURE__ */ jsx(
|
|
2031
|
+
"div",
|
|
2032
|
+
{
|
|
2033
|
+
ref: refFor(itemKey),
|
|
2034
|
+
role: "group",
|
|
2035
|
+
tabIndex,
|
|
2036
|
+
"aria-label": label,
|
|
2037
|
+
"data-graph-key": itemKey,
|
|
2038
|
+
className: "crewlet-graph-canvas__empty",
|
|
2039
|
+
style: { transform: `translate(${item.x}px, ${item.y}px)`, width: `${item.width}px`, height: `${item.height}px` },
|
|
2040
|
+
onFocus: (event) => {
|
|
2041
|
+
if (event.target === event.currentTarget) onFocusItem(itemKey);
|
|
2042
|
+
},
|
|
2043
|
+
onKeyDown: onItemKey,
|
|
2044
|
+
children
|
|
2045
|
+
}
|
|
2046
|
+
)
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
2049
|
+
var SHAPE_CORNER = 2;
|
|
2050
|
+
var SHAPE_NOTCH = 4;
|
|
2051
|
+
function Shapes({
|
|
2052
|
+
layout,
|
|
2053
|
+
nodeById,
|
|
2054
|
+
dimmed,
|
|
2055
|
+
worstOf,
|
|
2056
|
+
selectedKey
|
|
2057
|
+
}) {
|
|
2058
|
+
const paths = useMemo(() => {
|
|
2059
|
+
const out = { card: "", faded: "", dashed: "", danger: "", warning: "", info: "", selected: "" };
|
|
2060
|
+
const radius = SHAPE_CORNER;
|
|
2061
|
+
for (const item of layout.items) {
|
|
2062
|
+
if (item.kind !== "node" && item.kind !== "summary") continue;
|
|
2063
|
+
const node = item.kind === "node" ? nodeById.get(item.id) : void 0;
|
|
2064
|
+
const rect = roundRect(item, radius);
|
|
2065
|
+
if (item.key === selectedKey) out.selected += rect;
|
|
2066
|
+
else if (dimmed?.(item.key)) out.faded += rect;
|
|
2067
|
+
else if (node?.unconfirmed) out.dashed += rect;
|
|
2068
|
+
else out.card += rect;
|
|
2069
|
+
const attention = node ? node.attention : worstOf(layout.groupById.get(item.id)?.members ?? []);
|
|
2070
|
+
if (attention) out[attention.tone] += `M${item.x} ${item.y}h${SHAPE_NOTCH}v${item.height}h${-SHAPE_NOTCH}Z`;
|
|
2071
|
+
}
|
|
2072
|
+
return out;
|
|
2073
|
+
}, [layout, nodeById, dimmed, worstOf, selectedKey]);
|
|
2074
|
+
return /* @__PURE__ */ jsxs(
|
|
2075
|
+
"svg",
|
|
2076
|
+
{
|
|
2077
|
+
className: "crewlet-graph-canvas__shapes",
|
|
2078
|
+
width: layout.bounds.width,
|
|
2079
|
+
height: layout.bounds.height,
|
|
2080
|
+
"aria-hidden": "true",
|
|
2081
|
+
children: [
|
|
2082
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "card", d: paths.card }),
|
|
2083
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "faded", d: paths.faded }),
|
|
2084
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "dashed", d: paths.dashed }),
|
|
2085
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "selected", d: paths.selected }),
|
|
2086
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "danger", d: paths.danger }),
|
|
2087
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "warning", d: paths.warning }),
|
|
2088
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "info", d: paths.info })
|
|
2089
|
+
]
|
|
2090
|
+
}
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
function roundRect(rect, r) {
|
|
2094
|
+
const { x, y, width: w, height: h } = rect;
|
|
2095
|
+
return `M${x + r} ${y}h${w - 2 * r}q${r} 0 ${r} ${r}v${h - 2 * r}q0 ${r} ${-r} ${r}h${-(w - 2 * r)}q${-r} 0 ${-r} ${-r}v${-(h - 2 * r)}q0 ${-r} ${r} ${-r}Z`;
|
|
2096
|
+
}
|
|
2097
|
+
function placedStyle(rect) {
|
|
2098
|
+
return { transform: `translate(${rect.x}px, ${rect.y}px)`, width: `${rect.width}px`, height: `${rect.height}px` };
|
|
2099
|
+
}
|
|
2100
|
+
function intersects(a, b) {
|
|
2101
|
+
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
2102
|
+
}
|
|
2103
|
+
function graphWindow(was, view, viewport) {
|
|
2104
|
+
const detail = view.k >= GRAPH_CANVAS_DETAIL_ZOOM;
|
|
2105
|
+
const visible = {
|
|
2106
|
+
x: -view.x / view.k,
|
|
2107
|
+
y: -view.y / view.k,
|
|
2108
|
+
width: viewport.width / view.k,
|
|
2109
|
+
height: viewport.height / view.k
|
|
2110
|
+
};
|
|
2111
|
+
const roomy = {
|
|
2112
|
+
x: visible.x - visible.width / 2,
|
|
2113
|
+
y: visible.y - visible.height / 2,
|
|
2114
|
+
width: visible.width * 2,
|
|
2115
|
+
height: visible.height * 2
|
|
2116
|
+
};
|
|
2117
|
+
if (was && was.detail === detail) {
|
|
2118
|
+
const inside = visible.x >= was.rect.x && visible.y >= was.rect.y && visible.x + visible.width <= was.rect.x + was.rect.width && visible.y + visible.height <= was.rect.y + was.rect.height;
|
|
2119
|
+
const tooLarge = was.rect.width * was.rect.height > 4 * roomy.width * roomy.height;
|
|
2120
|
+
if (inside && !tooLarge) return was;
|
|
2121
|
+
}
|
|
2122
|
+
return { rect: roomy, detail };
|
|
2123
|
+
}
|
|
2124
|
+
function typeAhead(layout, from, text, nameOf) {
|
|
2125
|
+
const order = layout.lanes.flatMap((lane) => lane.items);
|
|
2126
|
+
const lower = text.toLocaleLowerCase();
|
|
2127
|
+
const cycling = [...lower].every((character) => character === lower[0]);
|
|
2128
|
+
const needle = cycling ? lower[0] : lower;
|
|
2129
|
+
const at = order.indexOf(from);
|
|
2130
|
+
const begin = at < 0 ? 0 : at + (cycling ? 1 : 0);
|
|
2131
|
+
for (let step = 0; step < order.length; step++) {
|
|
2132
|
+
const key = order[(begin + step) % order.length];
|
|
2133
|
+
if (nameOf(layout.itemByKey.get(key)).toLocaleLowerCase().startsWith(needle)) return key;
|
|
2134
|
+
}
|
|
2135
|
+
return null;
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
export { GRAPH_CANVAS_DETAIL_ZOOM, GRAPH_CANVAS_FIT_FLOOR, GRAPH_CANVAS_FLOW_LIMIT, GRAPH_CANVAS_LABELS, GRAPH_CANVAS_NARROW_WIDTH, GRAPH_CANVAS_OPEN_ZOOM, GRAPH_EDGE_FAMILIES, GRAPH_ORDER_SWEEPS, GraphCanvas, graphItemKey, graphNeighbourhood, graphReach, graphStep, graphTrunks, graphWindow, layoutGraph, routeGraphEdges };
|