@crewlethq/ui 0.121.1 → 0.122.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 +1 -1
- package/dist/AvatarPicker/index.js +2 -2
- package/dist/GraphCanvas/GraphCanvas.d.ts +187 -0
- package/dist/GraphCanvas/index.d.ts +9 -0
- package/dist/GraphCanvas/index.js +21 -0
- package/dist/GraphCanvas/layout.d.ts +201 -0
- package/dist/GraphCanvas/reach.d.ts +27 -0
- package/dist/GraphCanvas/walk.d.ts +20 -0
- package/dist/GraphCanvas-RSBMO2AF.css +388 -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/OrgTable/index.js +3 -3
- package/dist/PropertyList/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/{chunk-65AMIQSW.js → chunk-4PEPSGCZ.js} +4 -2
- package/dist/chunk-6KPHU4EB.js +1770 -0
- package/dist/{chunk-5LIWAA7S.js → chunk-CXFMNOPV.js} +15 -6
- package/dist/{chunk-3RKS3DLF.js → chunk-ENYHABQJ.js} +1 -1
- package/dist/{chunk-KZTR3V2P.js → chunk-J44ZIWGH.js} +11 -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 +414 -2
- package/package.json +3 -3
- package/dist/{Editor-JCAYNXQX.js → Editor-SBHTMAEK.js} +1 -1
- package/dist/{chunk-WLL3PFI3.js → chunk-2DZV4PHK.js} +1 -1
- package/dist/{chunk-YCT7LRYR.js → chunk-JWUIGUIS.js} +1 -1
- package/dist/{chunk-S2ZUAI6C.js → chunk-MDD6K5M4.js} +1 -1
- /package/dist/{chunk-33NGH63Z.js → chunk-QV3WVNRA.js} +0 -0
|
@@ -0,0 +1,1770 @@
|
|
|
1
|
+
import { useMeasuredSizes, isTypeAheadKey, typeAheadBuffer } from './chunk-MY374UUD.js';
|
|
2
|
+
import { IconTile } from './chunk-3LI4TRUR.js';
|
|
3
|
+
import { fitView, CANVAS_FIT_PADDING, Canvas } from './chunk-GKHZSNIV.js';
|
|
4
|
+
import { Text } from './chunk-XLMURU75.js';
|
|
5
|
+
import { StatusDot } from './chunk-QRE6JCHS.js';
|
|
6
|
+
import { VisuallyHidden } from './chunk-RRRK2KB6.js';
|
|
7
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
8
|
+
import './GraphCanvas-RSBMO2AF.css';
|
|
9
|
+
import { memo, useMemo, useId, useCallback, useState, useRef, useLayoutEffect, useImperativeHandle } from 'react';
|
|
10
|
+
import { ChevronDownGlyph, ChevronRightGlyph } from '@crewlethq/icons/glyphs';
|
|
11
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
12
|
+
|
|
13
|
+
// src/GraphCanvas/layout.ts
|
|
14
|
+
var GRAPH_ORDER_SWEEPS = 8;
|
|
15
|
+
var TRACK_STEP = 6;
|
|
16
|
+
var STREET_TRACK_STEP = 4;
|
|
17
|
+
var CORNER = 6;
|
|
18
|
+
var ARROW_LENGTH = 7;
|
|
19
|
+
var ARROW_HALF = 3.5;
|
|
20
|
+
var PORT_INSET = 8;
|
|
21
|
+
function graphItemKey(kind, id) {
|
|
22
|
+
return `${kind}:${id}`;
|
|
23
|
+
}
|
|
24
|
+
function layoutGraph(input, metrics) {
|
|
25
|
+
const { bands, nodes, open } = input;
|
|
26
|
+
const groups = input.groups ?? [];
|
|
27
|
+
const laneBand = /* @__PURE__ */ new Map();
|
|
28
|
+
bands.forEach(
|
|
29
|
+
(band, b) => band.lanes.forEach((lane) => {
|
|
30
|
+
if (laneBand.has(lane)) throw new Error(`GraphCanvas: lane "${lane}" is listed twice`);
|
|
31
|
+
laneBand.set(lane, b);
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
const groupLane = /* @__PURE__ */ new Map();
|
|
35
|
+
for (const group of groups) {
|
|
36
|
+
if (groupLane.has(group.id)) throw new Error(`GraphCanvas: group "${group.id}" is listed twice`);
|
|
37
|
+
if (!laneBand.has(group.lane))
|
|
38
|
+
throw new Error(`GraphCanvas: group "${group.id}" is in unknown lane "${group.lane}"`);
|
|
39
|
+
groupLane.set(group.id, group.lane);
|
|
40
|
+
}
|
|
41
|
+
const seen = /* @__PURE__ */ new Set();
|
|
42
|
+
for (const node of nodes) {
|
|
43
|
+
if (seen.has(node.id)) throw new Error(`GraphCanvas: entry "${node.id}" is listed twice`);
|
|
44
|
+
seen.add(node.id);
|
|
45
|
+
if (!laneBand.has(node.lane)) throw new Error(`GraphCanvas: entry "${node.id}" is in unknown lane "${node.lane}"`);
|
|
46
|
+
if (node.group !== void 0 && groupLane.get(node.group) !== node.lane) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`GraphCanvas: entry "${node.id}" names group "${node.group}", which is not in lane "${node.lane}"`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const blocksOf = /* @__PURE__ */ new Map();
|
|
53
|
+
const groupBlock = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const band of bands) for (const lane of band.lanes) blocksOf.set(lane, []);
|
|
55
|
+
nodes.forEach((node, index) => {
|
|
56
|
+
const list = blocksOf.get(node.lane);
|
|
57
|
+
if (node.group === void 0) {
|
|
58
|
+
list.push({ kind: "loose", id: node.id, members: [node.id], index });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let block = groupBlock.get(node.group);
|
|
62
|
+
if (!block) {
|
|
63
|
+
block = { kind: open(node.group) ? "group" : "closed", id: node.group, members: [], index };
|
|
64
|
+
groupBlock.set(node.group, block);
|
|
65
|
+
list.push(block);
|
|
66
|
+
}
|
|
67
|
+
block.members.push(node.id);
|
|
68
|
+
});
|
|
69
|
+
const keyOfNode = /* @__PURE__ */ new Map();
|
|
70
|
+
for (const blocks of blocksOf.values()) {
|
|
71
|
+
for (const block of blocks) {
|
|
72
|
+
for (const id of block.members) {
|
|
73
|
+
keyOfNode.set(id, block.kind === "closed" ? graphItemKey("summary", block.id) : graphItemKey("node", id));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const allLanes = bands.flatMap((band) => band.lanes);
|
|
78
|
+
const laneNumber = new Map(allLanes.map((lane, i) => [lane, i]));
|
|
79
|
+
const itemIndex = /* @__PURE__ */ new Map();
|
|
80
|
+
const itemLane = [];
|
|
81
|
+
for (const lane of allLanes) {
|
|
82
|
+
for (const block of blocksOf.get(lane)) {
|
|
83
|
+
const keys = block.kind === "closed" ? [graphItemKey("summary", block.id)] : block.members.map((id) => graphItemKey("node", id));
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
itemIndex.set(key, itemLane.length);
|
|
86
|
+
itemLane.push(laneNumber.get(lane));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const adjacent = itemLane.map(() => []);
|
|
91
|
+
for (const edge of input.edges) {
|
|
92
|
+
const a = itemIndex.get(keyOfNode.get(edge.from) ?? "");
|
|
93
|
+
const b = itemIndex.get(keyOfNode.get(edge.to) ?? "");
|
|
94
|
+
if (a === void 0 || b === void 0 || a === b || itemLane[a] === itemLane[b]) continue;
|
|
95
|
+
adjacent[a].push(b);
|
|
96
|
+
adjacent[b].push(a);
|
|
97
|
+
}
|
|
98
|
+
const pitch = metrics.cardHeight + metrics.rowGap;
|
|
99
|
+
const emptyRowsOf = (lane) => {
|
|
100
|
+
const height = input.emptyHeights?.get(lane);
|
|
101
|
+
if (height === void 0 || height <= 0) return 1;
|
|
102
|
+
return Math.max(1, Math.ceil((height + metrics.rowGap) / pitch));
|
|
103
|
+
};
|
|
104
|
+
const placeLane = (lane, span = laneCols.get(lane).span) => {
|
|
105
|
+
const blocks = blocksOf.get(lane);
|
|
106
|
+
const cells = [];
|
|
107
|
+
if (blocks.length === 0) {
|
|
108
|
+
const rows = emptyRowsOf(lane);
|
|
109
|
+
cells.push({ key: graphItemKey("empty", lane), kind: "empty", id: lane, col: 0, row: 0, cols: span, rows });
|
|
110
|
+
return { cells, rows };
|
|
111
|
+
}
|
|
112
|
+
let row = 0;
|
|
113
|
+
let col = 0;
|
|
114
|
+
const cell = (key, kind, id) => {
|
|
115
|
+
cells.push({ key, kind, id, col, row, cols: 1, rows: 1 });
|
|
116
|
+
col += 1;
|
|
117
|
+
if (col === span) {
|
|
118
|
+
col = 0;
|
|
119
|
+
row += 1;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
for (const block of blocks) {
|
|
123
|
+
if (block.kind === "loose") cell(graphItemKey("node", block.id), "node", block.id);
|
|
124
|
+
else if (block.kind === "closed") cell(graphItemKey("summary", block.id), "summary", block.id);
|
|
125
|
+
else {
|
|
126
|
+
if (col > 0) {
|
|
127
|
+
col = 0;
|
|
128
|
+
row += 1;
|
|
129
|
+
}
|
|
130
|
+
cells.push({
|
|
131
|
+
key: graphItemKey("head", block.id),
|
|
132
|
+
kind: "head",
|
|
133
|
+
id: block.id,
|
|
134
|
+
col: 0,
|
|
135
|
+
row,
|
|
136
|
+
cols: span,
|
|
137
|
+
rows: 1
|
|
138
|
+
});
|
|
139
|
+
row += 1;
|
|
140
|
+
for (const id of block.members) cell(graphItemKey("node", id), "node", id);
|
|
141
|
+
if (col > 0) {
|
|
142
|
+
col = 0;
|
|
143
|
+
row += 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (col > 0) row += 1;
|
|
148
|
+
return { cells, rows: row };
|
|
149
|
+
};
|
|
150
|
+
const columns = Math.max(1, ...bands.map((band) => band.lanes.length));
|
|
151
|
+
const laneCols = /* @__PURE__ */ new Map();
|
|
152
|
+
for (const band of bands) {
|
|
153
|
+
const base = Math.floor(columns / Math.max(1, band.lanes.length));
|
|
154
|
+
const spans = band.lanes.map(() => base);
|
|
155
|
+
const rowsAt = (i, span) => {
|
|
156
|
+
const lane = band.lanes[i];
|
|
157
|
+
return blocksOf.get(lane).length === 0 ? 1 : placeLane(lane, span).rows;
|
|
158
|
+
};
|
|
159
|
+
for (let spare = columns - base * band.lanes.length; spare > 0; spare--) {
|
|
160
|
+
let pick = 0;
|
|
161
|
+
let best = [-1, -1, -Infinity];
|
|
162
|
+
spans.forEach((span, i) => {
|
|
163
|
+
const now = rowsAt(i, span);
|
|
164
|
+
const gains = now > rowsAt(i, span + 1);
|
|
165
|
+
const score = [gains ? 1 : 0, gains ? now : 0, -span];
|
|
166
|
+
if (score[0] > best[0] || score[0] === best[0] && (score[1] > best[1] || score[1] === best[1] && score[2] > best[2])) {
|
|
167
|
+
best = score;
|
|
168
|
+
pick = i;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
spans[pick] += 1;
|
|
172
|
+
}
|
|
173
|
+
let col = 0;
|
|
174
|
+
band.lanes.forEach((lane, i) => {
|
|
175
|
+
laneCols.set(lane, { col, span: spans[i] });
|
|
176
|
+
col += spans[i];
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const rank = new Float64Array(itemLane.length);
|
|
180
|
+
const rankLane = (lane) => {
|
|
181
|
+
const b = laneBand.get(lane);
|
|
182
|
+
const { col } = laneCols.get(lane);
|
|
183
|
+
for (const cell of placeLane(lane).cells) {
|
|
184
|
+
const index = itemIndex.get(cell.key);
|
|
185
|
+
if (index !== void 0) rank[index] = b * 1e6 + cell.row * columns + col + cell.col;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
allLanes.forEach(rankLane);
|
|
189
|
+
const barycentre = (index) => {
|
|
190
|
+
const list = adjacent[index];
|
|
191
|
+
if (list.length === 0) return NaN;
|
|
192
|
+
let sum = 0;
|
|
193
|
+
for (const other of list) sum += rank[other];
|
|
194
|
+
return sum / list.length;
|
|
195
|
+
};
|
|
196
|
+
for (let sweep = 0; sweep < GRAPH_ORDER_SWEEPS; sweep++) {
|
|
197
|
+
const order = sweep % 2 === 0 ? allLanes : [...allLanes].reverse();
|
|
198
|
+
for (const lane of order) {
|
|
199
|
+
const blocks = blocksOf.get(lane);
|
|
200
|
+
if (blocks.length === 0) continue;
|
|
201
|
+
const keyed = blocks.map((block, position) => {
|
|
202
|
+
const indices = block.kind === "closed" ? [itemIndex.get(graphItemKey("summary", block.id))] : block.members.map((id) => itemIndex.get(graphItemKey("node", id)));
|
|
203
|
+
const bary = indices.map(barycentre);
|
|
204
|
+
if (block.kind === "group") {
|
|
205
|
+
const scored = block.members.map((id, i) => ({
|
|
206
|
+
id,
|
|
207
|
+
i,
|
|
208
|
+
at: Number.isNaN(bary[i]) ? rank[indices[i]] : bary[i]
|
|
209
|
+
}));
|
|
210
|
+
scored.sort((a, b) => a.at - b.at || a.i - b.i);
|
|
211
|
+
block.members = scored.map((one) => one.id);
|
|
212
|
+
}
|
|
213
|
+
let sum = 0;
|
|
214
|
+
let count = 0;
|
|
215
|
+
for (const value of bary) {
|
|
216
|
+
if (Number.isNaN(value)) continue;
|
|
217
|
+
sum += value;
|
|
218
|
+
count += 1;
|
|
219
|
+
}
|
|
220
|
+
return { block, position, at: count > 0 ? sum / count : rank[indices[0]] };
|
|
221
|
+
});
|
|
222
|
+
keyed.sort((a, b) => a.at - b.at || a.position - b.position);
|
|
223
|
+
blocksOf.set(
|
|
224
|
+
lane,
|
|
225
|
+
keyed.map((one) => one.block)
|
|
226
|
+
);
|
|
227
|
+
rankLane(lane);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const { cardWidth, cardHeight, gutter, rowGap, laneHead, bandHead, bandGap, lanePad, margin } = metrics;
|
|
231
|
+
const colX = Array.from({ length: columns }, (_, c) => margin + gutter / 2 + c * (cardWidth + gutter));
|
|
232
|
+
const channelX = Array.from({ length: columns + 1 }, (_, c) => margin + c * (cardWidth + gutter));
|
|
233
|
+
const placedLanes = new Map(allLanes.map((lane) => [lane, placeLane(lane)]));
|
|
234
|
+
const bandRows = bands.map((band) => Math.max(1, ...band.lanes.map((lane) => placedLanes.get(lane).rows)));
|
|
235
|
+
const bandsPlaced = [];
|
|
236
|
+
const bandRowsTop = [];
|
|
237
|
+
let y = margin;
|
|
238
|
+
bands.forEach((band, b) => {
|
|
239
|
+
const title = band.titled ? { x: channelX[0], y, width: channelX[columns] - channelX[0], height: bandHead } : null;
|
|
240
|
+
if (band.titled) y += bandHead;
|
|
241
|
+
const rowsTop = y + laneHead;
|
|
242
|
+
bandRowsTop.push(rowsTop);
|
|
243
|
+
bandsPlaced.push({ id: band.id, index: b, title, rowsTop, rows: bandRows[b] });
|
|
244
|
+
y = rowsTop + bandRows[b] * pitch - rowGap + lanePad + (b < bands.length - 1 ? bandGap : 0);
|
|
245
|
+
});
|
|
246
|
+
const bounds = { x: 0, y: 0, width: channelX[columns] + margin, height: y + margin };
|
|
247
|
+
const items = [];
|
|
248
|
+
const itemByKey = /* @__PURE__ */ new Map();
|
|
249
|
+
const lanes = [];
|
|
250
|
+
const occupied = bands.map((_, b) => new Uint8Array(bandRows[b] * columns));
|
|
251
|
+
const rowY = (b, row) => bandRowsTop[b] + row * pitch;
|
|
252
|
+
for (const lane of allLanes) {
|
|
253
|
+
const b = laneBand.get(lane);
|
|
254
|
+
const { col, span } = laneCols.get(lane);
|
|
255
|
+
const { cells } = placedLanes.get(lane);
|
|
256
|
+
const left = colX[col];
|
|
257
|
+
const right = colX[col + span - 1] + cardWidth;
|
|
258
|
+
const rowsTop = bandRowsTop[b];
|
|
259
|
+
const rowsBottom = rowsTop + bandRows[b] * pitch - rowGap;
|
|
260
|
+
const head = { x: left, y: rowsTop - laneHead, width: right - left, height: laneHead };
|
|
261
|
+
const keys = [];
|
|
262
|
+
for (const cell of cells) {
|
|
263
|
+
const x = colX[col + cell.col];
|
|
264
|
+
const width = cell.cols === 1 || cell.kind === "head" ? cardWidth : colX[col + cell.col + cell.cols - 1] + cardWidth - x;
|
|
265
|
+
const top = rowY(b, cell.row) + (cell.kind === "head" ? cardHeight / 2 : 0);
|
|
266
|
+
const item = {
|
|
267
|
+
key: cell.key,
|
|
268
|
+
kind: cell.kind,
|
|
269
|
+
id: cell.id,
|
|
270
|
+
lane,
|
|
271
|
+
band: b,
|
|
272
|
+
col: col + cell.col,
|
|
273
|
+
row: cell.row,
|
|
274
|
+
cols: cell.cols,
|
|
275
|
+
rows: cell.rows,
|
|
276
|
+
x,
|
|
277
|
+
y: top,
|
|
278
|
+
width,
|
|
279
|
+
height: cell.kind === "head" ? cardHeight / 2 : cell.rows * pitch - rowGap
|
|
280
|
+
};
|
|
281
|
+
items.push(item);
|
|
282
|
+
itemByKey.set(item.key, item);
|
|
283
|
+
keys.push(item.key);
|
|
284
|
+
for (let r = cell.row; r < cell.row + cell.rows; r++) {
|
|
285
|
+
for (let c = item.col; c < item.col + cell.cols; c++) occupied[b][r * columns + c] = 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const count = (blocksOf.get(lane) ?? []).reduce((sum, block) => sum + block.members.length, 0);
|
|
289
|
+
lanes.push({
|
|
290
|
+
id: lane,
|
|
291
|
+
band: b,
|
|
292
|
+
col,
|
|
293
|
+
span,
|
|
294
|
+
rows: placedLanes.get(lane).rows,
|
|
295
|
+
panel: {
|
|
296
|
+
x: left - lanePad,
|
|
297
|
+
y: head.y,
|
|
298
|
+
width: right - left + 2 * lanePad,
|
|
299
|
+
height: rowsBottom + lanePad - head.y
|
|
300
|
+
},
|
|
301
|
+
head,
|
|
302
|
+
items: keys,
|
|
303
|
+
count
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
const groupsPlaced = [];
|
|
307
|
+
const boxBottoms = [];
|
|
308
|
+
for (const lane of allLanes) {
|
|
309
|
+
for (const block of blocksOf.get(lane)) {
|
|
310
|
+
if (block.kind === "loose") continue;
|
|
311
|
+
if (block.kind === "closed") {
|
|
312
|
+
groupsPlaced.push({ id: block.id, lane, open: false, box: null, members: [...block.members] });
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const head = itemByKey.get(graphItemKey("head", block.id));
|
|
316
|
+
const last = block.members.reduce((bottom2, id) => {
|
|
317
|
+
const item = itemByKey.get(graphItemKey("node", id));
|
|
318
|
+
return Math.max(bottom2, item.row);
|
|
319
|
+
}, head.row);
|
|
320
|
+
const { col, span } = laneCols.get(lane);
|
|
321
|
+
const top = head.y;
|
|
322
|
+
const bottom = rowY(head.band, last) + cardHeight + lanePad / 2;
|
|
323
|
+
groupsPlaced.push({
|
|
324
|
+
id: block.id,
|
|
325
|
+
lane,
|
|
326
|
+
open: true,
|
|
327
|
+
box: {
|
|
328
|
+
x: colX[col] - lanePad / 2,
|
|
329
|
+
y: top,
|
|
330
|
+
width: colX[col + span - 1] + cardWidth - colX[col] + lanePad,
|
|
331
|
+
height: bottom - top
|
|
332
|
+
},
|
|
333
|
+
members: [...block.members]
|
|
334
|
+
});
|
|
335
|
+
boxBottoms.push({ band: head.band, col, span, row: last });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const streets = [];
|
|
339
|
+
const empties = items.filter((item) => item.kind === "empty");
|
|
340
|
+
bands.forEach((_, b) => {
|
|
341
|
+
for (let row = 0; row < bandRows[b]; row++) {
|
|
342
|
+
const dirty = new Uint8Array(columns);
|
|
343
|
+
const blocked = new Uint8Array(columns);
|
|
344
|
+
for (const box of boxBottoms) {
|
|
345
|
+
if (box.band !== b || box.row !== row) continue;
|
|
346
|
+
for (let c = box.col; c < box.col + box.span; c++) dirty[c] = 1;
|
|
347
|
+
}
|
|
348
|
+
for (const empty of empties) {
|
|
349
|
+
if (empty.band !== b || row < empty.row || row >= empty.row + empty.rows - 1) continue;
|
|
350
|
+
for (let c = empty.col; c < empty.col + empty.cols; c++) blocked[c] = 1;
|
|
351
|
+
}
|
|
352
|
+
streets.push({ y: rowY(b, row) + cardHeight + rowGap / 2, band: b, gap: -1, dirty, blocked });
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
bandsPlaced.forEach((band, b) => {
|
|
356
|
+
if (b === 0) return;
|
|
357
|
+
const above = bandRowsTop[b - 1] + bandRows[b - 1] * pitch - rowGap + lanePad;
|
|
358
|
+
const below = band.title ? band.title.y : band.rowsTop - laneHead;
|
|
359
|
+
streets.push({
|
|
360
|
+
y: (above + below) / 2,
|
|
361
|
+
band: -1,
|
|
362
|
+
gap: b,
|
|
363
|
+
dirty: new Uint8Array(columns),
|
|
364
|
+
blocked: new Uint8Array(columns)
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
streets.sort((a, b) => a.y - b.y);
|
|
368
|
+
const bandStreets = bands.map(() => []);
|
|
369
|
+
const gapStreets = /* @__PURE__ */ new Map();
|
|
370
|
+
streets.forEach((street, i) => {
|
|
371
|
+
if (street.band >= 0) bandStreets[street.band].push(i);
|
|
372
|
+
else gapStreets.set(street.gap, i);
|
|
373
|
+
});
|
|
374
|
+
const grid = { colX, channelX, streets, bandStreets, gapStreets, occupied, bandRows, bandRowsTop };
|
|
375
|
+
const itemOfNode = keyOfNode;
|
|
376
|
+
const partial = { metrics, columns, itemByKey, itemOfNode, grid };
|
|
377
|
+
const routed = routeAll(partial, input.edges);
|
|
378
|
+
return {
|
|
379
|
+
bounds,
|
|
380
|
+
metrics,
|
|
381
|
+
columns,
|
|
382
|
+
bands: bandsPlaced,
|
|
383
|
+
lanes,
|
|
384
|
+
laneById: new Map(lanes.map((lane) => [lane.id, lane])),
|
|
385
|
+
items,
|
|
386
|
+
itemByKey,
|
|
387
|
+
itemOfNode,
|
|
388
|
+
groups: groupsPlaced,
|
|
389
|
+
groupById: new Map(groupsPlaced.map((group) => [group.id, group])),
|
|
390
|
+
routes: routed.routes,
|
|
391
|
+
routeOfEdge: routed.routeOfEdge,
|
|
392
|
+
grid
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function routeGraphEdges(layout, edges) {
|
|
396
|
+
return routeAll(layout, edges).routes;
|
|
397
|
+
}
|
|
398
|
+
function routeAll(layout, edges) {
|
|
399
|
+
const { itemByKey, itemOfNode, grid, columns, metrics } = layout;
|
|
400
|
+
const plans = /* @__PURE__ */ new Map();
|
|
401
|
+
const routeOfEdge = /* @__PURE__ */ new Map();
|
|
402
|
+
for (const edge of edges) {
|
|
403
|
+
const a = itemOfNode.get(edge.from);
|
|
404
|
+
const b = itemOfNode.get(edge.to);
|
|
405
|
+
if (a === void 0 || b === void 0 || a === b) continue;
|
|
406
|
+
const key = `${a}>${b}`;
|
|
407
|
+
routeOfEdge.set(edge.id, key);
|
|
408
|
+
const known = plans.get(key);
|
|
409
|
+
if (known) {
|
|
410
|
+
known.edges.push(edge.id);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
plans.set(key, plan(key, itemByKey.get(a), itemByKey.get(b), edge.id, grid, columns, metrics));
|
|
414
|
+
}
|
|
415
|
+
const list = [...plans.values()];
|
|
416
|
+
const sides = /* @__PURE__ */ new Map();
|
|
417
|
+
const attach = (item, side, entry) => {
|
|
418
|
+
const key = `${item.key}|${side}`;
|
|
419
|
+
let list2 = sides.get(key);
|
|
420
|
+
if (!list2) sides.set(key, list2 = []);
|
|
421
|
+
list2.push(entry);
|
|
422
|
+
};
|
|
423
|
+
const centre2 = (item) => item.y + item.height / 2;
|
|
424
|
+
for (const one of list) {
|
|
425
|
+
attach(one.from, one.exit, {
|
|
426
|
+
plan: one,
|
|
427
|
+
end: "from",
|
|
428
|
+
toward: one.street === null ? centre2(one.to) : grid.streets[one.street].y
|
|
429
|
+
});
|
|
430
|
+
attach(one.to, one.entry, {
|
|
431
|
+
plan: one,
|
|
432
|
+
end: "to",
|
|
433
|
+
toward: one.street === null ? centre2(one.from) : grid.streets[one.street].y
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
for (const [key, entries] of sides) {
|
|
437
|
+
const item = itemByKey.get(key.slice(0, key.lastIndexOf("|")));
|
|
438
|
+
entries.sort((a, b) => a.toward - b.toward || byText(a.plan.key, b.plan.key));
|
|
439
|
+
const top = item.y + Math.min(PORT_INSET, item.height / 4);
|
|
440
|
+
const room = item.height - 2 * (top - item.y);
|
|
441
|
+
entries.forEach((entry, i) => {
|
|
442
|
+
const y = entries.length === 1 ? centre2(item) : top + room * (i + 0.5) / entries.length;
|
|
443
|
+
if (entry.end === "from") entry.plan.fromY = y;
|
|
444
|
+
else entry.plan.toY = y;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
const verticals = /* @__PURE__ */ new Map();
|
|
448
|
+
const horizontals = /* @__PURE__ */ new Map();
|
|
449
|
+
const push = (map, key, run) => {
|
|
450
|
+
let runs = map.get(key);
|
|
451
|
+
if (!runs) map.set(key, runs = []);
|
|
452
|
+
runs.push(run);
|
|
453
|
+
};
|
|
454
|
+
for (const one of list) {
|
|
455
|
+
if (one.straight) {
|
|
456
|
+
push(verticals, one.in, {
|
|
457
|
+
plan: one,
|
|
458
|
+
which: "in",
|
|
459
|
+
lo: Math.min(one.fromY, one.toY),
|
|
460
|
+
hi: Math.max(one.fromY, one.toY)
|
|
461
|
+
});
|
|
462
|
+
} else if (one.street === null) {
|
|
463
|
+
push(verticals, one.out, {
|
|
464
|
+
plan: one,
|
|
465
|
+
which: "out",
|
|
466
|
+
lo: Math.min(one.fromY, one.toY),
|
|
467
|
+
hi: Math.max(one.fromY, one.toY)
|
|
468
|
+
});
|
|
469
|
+
} else {
|
|
470
|
+
const sy = grid.streets[one.street].y;
|
|
471
|
+
push(verticals, one.out, { plan: one, which: "out", lo: Math.min(one.fromY, sy), hi: Math.max(one.fromY, sy) });
|
|
472
|
+
push(verticals, one.in, { plan: one, which: "in", lo: Math.min(sy, one.toY), hi: Math.max(sy, one.toY) });
|
|
473
|
+
const ax = grid.channelX[one.out];
|
|
474
|
+
const bx = grid.channelX[one.in];
|
|
475
|
+
push(horizontals, one.street, { plan: one, which: "street", lo: Math.min(ax, bx), hi: Math.max(ax, bx) });
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const verticalRoom = Math.max(0, metrics.gutter - 2 * metrics.lanePad);
|
|
479
|
+
for (const [channel, runs] of verticals) {
|
|
480
|
+
const offsets = assignTracks(runs, TRACK_STEP, verticalRoom);
|
|
481
|
+
runs.forEach((run, i) => {
|
|
482
|
+
const x = grid.channelX[channel] + offsets[i];
|
|
483
|
+
if (run.which === "out") run.plan.outX = x;
|
|
484
|
+
else run.plan.inX = x;
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
for (const [street, runs] of horizontals) {
|
|
488
|
+
const offsets = assignTracks(runs, STREET_TRACK_STEP, Math.max(0, metrics.rowGap - 4));
|
|
489
|
+
runs.forEach((run, i) => {
|
|
490
|
+
run.plan.streetY = grid.streets[street].y + offsets[i];
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
const routes = list.map((one) => {
|
|
494
|
+
const startX = one.exit === "right" ? one.from.x + one.from.width : one.from.x;
|
|
495
|
+
const endX = one.entry === "right" ? one.to.x + one.to.width : one.to.x;
|
|
496
|
+
let points;
|
|
497
|
+
if (one.straight) {
|
|
498
|
+
points = [
|
|
499
|
+
{ x: startX, y: one.fromY },
|
|
500
|
+
{ x: one.inX, y: one.fromY },
|
|
501
|
+
{ x: one.inX, y: one.toY },
|
|
502
|
+
{ x: endX, y: one.toY }
|
|
503
|
+
];
|
|
504
|
+
} else if (one.street === null) {
|
|
505
|
+
points = [
|
|
506
|
+
{ x: startX, y: one.fromY },
|
|
507
|
+
{ x: one.outX, y: one.fromY },
|
|
508
|
+
{ x: one.outX, y: one.toY },
|
|
509
|
+
{ x: endX, y: one.toY }
|
|
510
|
+
];
|
|
511
|
+
} else {
|
|
512
|
+
points = [
|
|
513
|
+
{ x: startX, y: one.fromY },
|
|
514
|
+
{ x: one.outX, y: one.fromY },
|
|
515
|
+
{ x: one.outX, y: one.streetY },
|
|
516
|
+
{ x: one.inX, y: one.streetY },
|
|
517
|
+
{ x: one.inX, y: one.toY },
|
|
518
|
+
{ x: endX, y: one.toY }
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
points = simplify(points);
|
|
522
|
+
const direction = one.entry === "right" ? -1 : 1;
|
|
523
|
+
const base = { x: endX - direction * ARROW_LENGTH, y: one.toY };
|
|
524
|
+
const drawn = [...points.slice(0, -1), base];
|
|
525
|
+
return {
|
|
526
|
+
key: one.key,
|
|
527
|
+
from: one.from.key,
|
|
528
|
+
to: one.to.key,
|
|
529
|
+
edges: one.edges,
|
|
530
|
+
points,
|
|
531
|
+
d: pathOf(drawn),
|
|
532
|
+
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`,
|
|
533
|
+
box: boxOf(points)
|
|
534
|
+
};
|
|
535
|
+
});
|
|
536
|
+
return { routes, routeOfEdge };
|
|
537
|
+
}
|
|
538
|
+
function plan(key, from, to, edge, grid, columns, metrics) {
|
|
539
|
+
const forward = to.col > from.col;
|
|
540
|
+
const back = to.col < from.col;
|
|
541
|
+
const exit = back ? "left" : "right";
|
|
542
|
+
const entry = forward ? "left" : "right";
|
|
543
|
+
const out = forward ? from.col + 1 : back ? from.col : from.col + 1;
|
|
544
|
+
const into = forward ? to.col : back ? to.col + 1 : to.col + 1;
|
|
545
|
+
const fromY = from.y + from.height / 2;
|
|
546
|
+
const toY = to.y + to.height / 2;
|
|
547
|
+
const base = {
|
|
548
|
+
key,
|
|
549
|
+
from,
|
|
550
|
+
to,
|
|
551
|
+
edges: [edge],
|
|
552
|
+
exit,
|
|
553
|
+
entry,
|
|
554
|
+
out,
|
|
555
|
+
in: into,
|
|
556
|
+
street: null,
|
|
557
|
+
straight: false,
|
|
558
|
+
fromY,
|
|
559
|
+
toY,
|
|
560
|
+
outX: grid.channelX[out],
|
|
561
|
+
inX: grid.channelX[into],
|
|
562
|
+
streetY: 0
|
|
563
|
+
};
|
|
564
|
+
if (out === into && from.band === to.band) return base;
|
|
565
|
+
if (from.band === to.band && from.row === to.row) {
|
|
566
|
+
const lo2 = Math.min(from.col, to.col) + 1;
|
|
567
|
+
const hi2 = Math.max(from.col, to.col) - 1;
|
|
568
|
+
const cells = grid.occupied[from.band];
|
|
569
|
+
let free = true;
|
|
570
|
+
for (let c = lo2; c <= hi2 && free; c++) if (cells[from.row * columns + c]) free = false;
|
|
571
|
+
if (free) return { ...base, straight: true };
|
|
572
|
+
}
|
|
573
|
+
const lo = Math.min(fromY, toY);
|
|
574
|
+
const hi = Math.max(fromY, toY);
|
|
575
|
+
const crossed = [];
|
|
576
|
+
for (let c = Math.min(out, into); c < Math.max(out, into); c++) crossed.push(c);
|
|
577
|
+
const pitch = metrics.cardHeight + metrics.rowGap;
|
|
578
|
+
if (from.band !== to.band) {
|
|
579
|
+
const gap = grid.gapStreets.get(from.band < to.band ? from.band + 1 : from.band);
|
|
580
|
+
return { ...base, street: gap ?? null };
|
|
581
|
+
}
|
|
582
|
+
const cost = (i) => {
|
|
583
|
+
const street = grid.streets[i];
|
|
584
|
+
const between = street.y >= lo && street.y <= hi;
|
|
585
|
+
let penalty = between ? 0 : pitch * 4;
|
|
586
|
+
for (const c of crossed) {
|
|
587
|
+
if (street.blocked[c]) penalty += pitch * 50;
|
|
588
|
+
else if (street.dirty[c]) penalty += pitch * 2;
|
|
589
|
+
}
|
|
590
|
+
return Math.abs(street.y - toY) + penalty;
|
|
591
|
+
};
|
|
592
|
+
const list = grid.bandStreets[from.band];
|
|
593
|
+
let at = 0;
|
|
594
|
+
let top = list.length;
|
|
595
|
+
while (at < top) {
|
|
596
|
+
const mid = at + top >> 1;
|
|
597
|
+
if (grid.streets[list[mid]].y < toY) at = mid + 1;
|
|
598
|
+
else top = mid;
|
|
599
|
+
}
|
|
600
|
+
let best = -1;
|
|
601
|
+
let bestCost = Infinity;
|
|
602
|
+
for (let i = at; i < list.length && grid.streets[list[i]].y - toY < bestCost; i++) {
|
|
603
|
+
const value = cost(list[i]);
|
|
604
|
+
if (value < bestCost) {
|
|
605
|
+
bestCost = value;
|
|
606
|
+
best = list[i];
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
for (let i = at - 1; i >= 0 && toY - grid.streets[list[i]].y < bestCost; i--) {
|
|
610
|
+
const value = cost(list[i]);
|
|
611
|
+
if (value < bestCost) {
|
|
612
|
+
bestCost = value;
|
|
613
|
+
best = list[i];
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return { ...base, street: best < 0 ? null : best };
|
|
617
|
+
}
|
|
618
|
+
function assignTracks(runs, step, room) {
|
|
619
|
+
const order = runs.map((_, i) => i).sort(
|
|
620
|
+
(a, b) => runs[a].lo - runs[b].lo || runs[a].hi - runs[b].hi || byText(runs[a].plan.key, runs[b].plan.key)
|
|
621
|
+
);
|
|
622
|
+
const track = new Array(runs.length).fill(0);
|
|
623
|
+
const busy = new Heap((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
624
|
+
const free = new Heap((a, b) => a - b);
|
|
625
|
+
let tracks = 0;
|
|
626
|
+
for (const i of order) {
|
|
627
|
+
const run = runs[i];
|
|
628
|
+
while (busy.size > 0 && busy.peek()[0] < run.lo - 1) free.push(busy.pop()[1]);
|
|
629
|
+
const t = free.size > 0 ? free.pop() : tracks++;
|
|
630
|
+
busy.push([run.hi, t]);
|
|
631
|
+
track[i] = t;
|
|
632
|
+
}
|
|
633
|
+
const most = Math.max(1, Math.floor(room / step) + 1);
|
|
634
|
+
return track.map((t) => {
|
|
635
|
+
const slot = t % most;
|
|
636
|
+
const side = slot % 2 === 0 ? 1 : -1;
|
|
637
|
+
return side * Math.ceil(slot / 2) * step;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
var Heap = class {
|
|
641
|
+
constructor(before) {
|
|
642
|
+
this.before = before;
|
|
643
|
+
}
|
|
644
|
+
before;
|
|
645
|
+
items = [];
|
|
646
|
+
get size() {
|
|
647
|
+
return this.items.length;
|
|
648
|
+
}
|
|
649
|
+
peek() {
|
|
650
|
+
return this.items[0];
|
|
651
|
+
}
|
|
652
|
+
push(item) {
|
|
653
|
+
const items = this.items;
|
|
654
|
+
items.push(item);
|
|
655
|
+
let at = items.length - 1;
|
|
656
|
+
while (at > 0) {
|
|
657
|
+
const parent = at - 1 >> 1;
|
|
658
|
+
if (this.before(items[at], items[parent]) >= 0) break;
|
|
659
|
+
[items[at], items[parent]] = [items[parent], items[at]];
|
|
660
|
+
at = parent;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
pop() {
|
|
664
|
+
const items = this.items;
|
|
665
|
+
const top = items[0];
|
|
666
|
+
const last = items.pop();
|
|
667
|
+
if (items.length > 0 && last !== void 0) {
|
|
668
|
+
items[0] = last;
|
|
669
|
+
let at = 0;
|
|
670
|
+
for (; ; ) {
|
|
671
|
+
const left = at * 2 + 1;
|
|
672
|
+
const right = left + 1;
|
|
673
|
+
let least = at;
|
|
674
|
+
if (left < items.length && this.before(items[left], items[least]) < 0) least = left;
|
|
675
|
+
if (right < items.length && this.before(items[right], items[least]) < 0) least = right;
|
|
676
|
+
if (least === at) break;
|
|
677
|
+
[items[at], items[least]] = [items[least], items[at]];
|
|
678
|
+
at = least;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return top;
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
function byText(a, b) {
|
|
685
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
686
|
+
}
|
|
687
|
+
function boxOf(points) {
|
|
688
|
+
let left = Infinity;
|
|
689
|
+
let top = Infinity;
|
|
690
|
+
let right = -Infinity;
|
|
691
|
+
let bottom = -Infinity;
|
|
692
|
+
for (const point of points) {
|
|
693
|
+
left = Math.min(left, point.x);
|
|
694
|
+
top = Math.min(top, point.y);
|
|
695
|
+
right = Math.max(right, point.x);
|
|
696
|
+
bottom = Math.max(bottom, point.y);
|
|
697
|
+
}
|
|
698
|
+
return { x: left, y: top - ARROW_HALF, width: right - left, height: bottom - top + 2 * ARROW_HALF };
|
|
699
|
+
}
|
|
700
|
+
function simplify(points) {
|
|
701
|
+
const out = [];
|
|
702
|
+
for (const point of points) {
|
|
703
|
+
const last = out[out.length - 1];
|
|
704
|
+
if (last && Math.abs(last.x - point.x) < 0.01 && Math.abs(last.y - point.y) < 0.01) continue;
|
|
705
|
+
const before = out[out.length - 2];
|
|
706
|
+
if (before && last) {
|
|
707
|
+
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;
|
|
708
|
+
if (inLine) out.pop();
|
|
709
|
+
}
|
|
710
|
+
out.push(point);
|
|
711
|
+
}
|
|
712
|
+
return out;
|
|
713
|
+
}
|
|
714
|
+
function pathOf(points) {
|
|
715
|
+
if (points.length === 0) return "";
|
|
716
|
+
let d = `M${n(points[0].x)} ${n(points[0].y)}`;
|
|
717
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
718
|
+
const a = points[i - 1];
|
|
719
|
+
const b = points[i];
|
|
720
|
+
const c = points[i + 1];
|
|
721
|
+
const r = Math.min(CORNER, distance(a, b) / 2, distance(b, c) / 2);
|
|
722
|
+
const inPoint = toward(b, a, r);
|
|
723
|
+
const outPoint = toward(b, c, r);
|
|
724
|
+
d += `L${n(inPoint.x)} ${n(inPoint.y)}Q${n(b.x)} ${n(b.y)} ${n(outPoint.x)} ${n(outPoint.y)}`;
|
|
725
|
+
}
|
|
726
|
+
const last = points[points.length - 1];
|
|
727
|
+
return `${d}L${n(last.x)} ${n(last.y)}`;
|
|
728
|
+
}
|
|
729
|
+
function distance(a, b) {
|
|
730
|
+
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
731
|
+
}
|
|
732
|
+
function toward(from, to, by) {
|
|
733
|
+
const length = distance(from, to);
|
|
734
|
+
if (length === 0) return from;
|
|
735
|
+
return { x: from.x + (to.x - from.x) * by / length, y: from.y + (to.y - from.y) * by / length };
|
|
736
|
+
}
|
|
737
|
+
function n(value) {
|
|
738
|
+
return String(Math.round(value * 10) / 10);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/GraphCanvas/reach.ts
|
|
742
|
+
function graphReach(edges, from, direction, depth) {
|
|
743
|
+
const out = /* @__PURE__ */ new Map();
|
|
744
|
+
const into = /* @__PURE__ */ new Map();
|
|
745
|
+
for (const edge of edges) {
|
|
746
|
+
if (edge.from === edge.to) continue;
|
|
747
|
+
let list = out.get(edge.from);
|
|
748
|
+
if (!list) out.set(edge.from, list = []);
|
|
749
|
+
list.push(edge);
|
|
750
|
+
list = into.get(edge.to);
|
|
751
|
+
if (!list) into.set(edge.to, list = []);
|
|
752
|
+
list.push(edge);
|
|
753
|
+
}
|
|
754
|
+
const nodes = /* @__PURE__ */ new Map([[from, 0]]);
|
|
755
|
+
const taken = /* @__PURE__ */ new Set();
|
|
756
|
+
const walk = (next, far) => {
|
|
757
|
+
const seen = /* @__PURE__ */ new Map([[from, 0]]);
|
|
758
|
+
let frontier = [from];
|
|
759
|
+
for (let hop = 1; hop <= depth && frontier.length > 0; hop++) {
|
|
760
|
+
const following = [];
|
|
761
|
+
for (const id of frontier) {
|
|
762
|
+
for (const edge of next(id) ?? []) {
|
|
763
|
+
const other = far(edge);
|
|
764
|
+
taken.add(edge.id);
|
|
765
|
+
if (seen.has(other)) continue;
|
|
766
|
+
seen.set(other, hop);
|
|
767
|
+
following.push(other);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
frontier = following;
|
|
771
|
+
}
|
|
772
|
+
for (const [id, hops] of seen) nodes.set(id, Math.min(hops, nodes.get(id) ?? Infinity));
|
|
773
|
+
};
|
|
774
|
+
if (direction === "up" || direction === "both")
|
|
775
|
+
walk(
|
|
776
|
+
(id) => into.get(id),
|
|
777
|
+
(edge) => edge.from
|
|
778
|
+
);
|
|
779
|
+
if (direction === "down" || direction === "both")
|
|
780
|
+
walk(
|
|
781
|
+
(id) => out.get(id),
|
|
782
|
+
(edge) => edge.to
|
|
783
|
+
);
|
|
784
|
+
return { nodes, edges: taken };
|
|
785
|
+
}
|
|
786
|
+
function graphNeighbourhood(edges, id) {
|
|
787
|
+
const nodes = /* @__PURE__ */ new Map([[id, 0]]);
|
|
788
|
+
const taken = /* @__PURE__ */ new Set();
|
|
789
|
+
for (const edge of edges) {
|
|
790
|
+
if (edge.from === edge.to) continue;
|
|
791
|
+
if (edge.from === id) {
|
|
792
|
+
nodes.set(edge.to, 1);
|
|
793
|
+
taken.add(edge.id);
|
|
794
|
+
} else if (edge.to === id) {
|
|
795
|
+
nodes.set(edge.from, 1);
|
|
796
|
+
taken.add(edge.id);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return { nodes, edges: taken };
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/GraphCanvas/walk.ts
|
|
803
|
+
function graphStep(layout, from, event) {
|
|
804
|
+
const item = layout.itemByKey.get(from);
|
|
805
|
+
if (!item) return void 0;
|
|
806
|
+
const lane = layout.laneById.get(item.lane);
|
|
807
|
+
const at = lane.items.indexOf(from);
|
|
808
|
+
const mod = event.ctrlKey === true || event.metaKey === true;
|
|
809
|
+
switch (event.key) {
|
|
810
|
+
case "ArrowDown":
|
|
811
|
+
return at < lane.items.length - 1 ? lane.items[at + 1] : acrossBands(layout, item, 1);
|
|
812
|
+
case "ArrowUp":
|
|
813
|
+
return at > 0 ? lane.items[at - 1] : acrossBands(layout, item, -1);
|
|
814
|
+
case "ArrowRight":
|
|
815
|
+
return besideLane(layout, item, lane, 1);
|
|
816
|
+
case "ArrowLeft":
|
|
817
|
+
return besideLane(layout, item, lane, -1);
|
|
818
|
+
case "Home":
|
|
819
|
+
return mod ? layout.lanes[0]?.items[0] ?? null : lane.items[0];
|
|
820
|
+
case "End": {
|
|
821
|
+
if (!mod) return lane.items[lane.items.length - 1];
|
|
822
|
+
const last = layout.lanes[layout.lanes.length - 1];
|
|
823
|
+
return last ? last.items[last.items.length - 1] : null;
|
|
824
|
+
}
|
|
825
|
+
default:
|
|
826
|
+
return void 0;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
var middle = (item) => item.y + item.height / 2;
|
|
830
|
+
var centre = (item) => item.x + item.width / 2;
|
|
831
|
+
function besideLane(layout, item, lane, step) {
|
|
832
|
+
const inBand = layout.lanes.filter((one) => one.band === lane.band);
|
|
833
|
+
const next = inBand[inBand.indexOf(lane) + step];
|
|
834
|
+
if (!next) return null;
|
|
835
|
+
return nearest(layout, next.items, (other) => Math.abs(middle(other) - middle(item)));
|
|
836
|
+
}
|
|
837
|
+
function acrossBands(layout, item, step) {
|
|
838
|
+
const band = item.band + step;
|
|
839
|
+
const lanes = layout.lanes.filter((one) => one.band === band);
|
|
840
|
+
if (lanes.length === 0) return null;
|
|
841
|
+
const x = centre(item);
|
|
842
|
+
let best = null;
|
|
843
|
+
let bestDistance = Infinity;
|
|
844
|
+
for (const lane of lanes) {
|
|
845
|
+
const left = lane.panel.x;
|
|
846
|
+
const right = lane.panel.x + lane.panel.width;
|
|
847
|
+
const distance2 = x < left ? left - x : x > right ? x - right : 0;
|
|
848
|
+
if (distance2 < bestDistance) {
|
|
849
|
+
bestDistance = distance2;
|
|
850
|
+
best = lane;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (!best) return null;
|
|
854
|
+
return step === 1 ? best.items[0] : best.items[best.items.length - 1];
|
|
855
|
+
}
|
|
856
|
+
function nearest(layout, keys, cost) {
|
|
857
|
+
let best = null;
|
|
858
|
+
let bestCost = Infinity;
|
|
859
|
+
for (const key of keys) {
|
|
860
|
+
const value = cost(layout.itemByKey.get(key));
|
|
861
|
+
if (value < bestCost) {
|
|
862
|
+
bestCost = value;
|
|
863
|
+
best = key;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return best;
|
|
867
|
+
}
|
|
868
|
+
var plural = (count, one, many) => `${count} ${count === 1 ? one : many}`;
|
|
869
|
+
var relationWords = (list) => list.map((one) => `${one.relation ?? "depends on"} ${one.name}`).join(", ");
|
|
870
|
+
var GRAPH_CANVAS_LABELS = {
|
|
871
|
+
zoomIn: "Zoom in",
|
|
872
|
+
zoomOut: "Zoom out",
|
|
873
|
+
fit: "Fit to view",
|
|
874
|
+
actualSize: "Zoom to 100%",
|
|
875
|
+
zoom: (percent) => `Zoom is ${percent} percent. Set a zoom level`,
|
|
876
|
+
zoomLevel: "Zoom level, percent",
|
|
877
|
+
done: "Done",
|
|
878
|
+
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.",
|
|
879
|
+
lane: (label, count) => `${label}, ${plural(count, "item", "items")}`,
|
|
880
|
+
entries: (count) => plural(count, "item", "items"),
|
|
881
|
+
openGroup: (label, count) => `${label}, ${plural(count, "item", "items")}, open`,
|
|
882
|
+
closedGroup: (label, count) => `${label}, ${plural(count, "item", "items")}, closed`,
|
|
883
|
+
emptyLane: (label) => `${label}, empty`,
|
|
884
|
+
unconfirmed: "Unconfirmed",
|
|
885
|
+
relations: (dependsOn, usedBy) => {
|
|
886
|
+
const parts = [];
|
|
887
|
+
if (dependsOn.length > 0) parts.push(`${relationWords(dependsOn)}.`);
|
|
888
|
+
if (usedBy.length > 0) parts.push(`Used by ${usedBy.map((one) => one.name).join(", ")}.`);
|
|
889
|
+
return parts.join(" ");
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
var GRAPH_CANVAS_DETAIL_ZOOM = 0.5;
|
|
893
|
+
var GRAPH_CANVAS_OPEN_ZOOM = 0.75;
|
|
894
|
+
var GRAPH_CANVAS_FIT_FLOOR = 0.02;
|
|
895
|
+
var CARD_PROBE = "crewlet:graph-canvas-card";
|
|
896
|
+
var GAP_PROBE = "crewlet:graph-canvas-gap";
|
|
897
|
+
var PAD_PROBE = "crewlet:graph-canvas-pad";
|
|
898
|
+
var HEAD_PROBE = "crewlet:graph-canvas-head";
|
|
899
|
+
var BAND_PROBE = "crewlet:graph-canvas-band";
|
|
900
|
+
var PROBES = [CARD_PROBE, GAP_PROBE, PAD_PROBE, HEAD_PROBE, BAND_PROBE];
|
|
901
|
+
var emptyProbe = (lane) => `crewlet:graph-canvas-empty:${lane}`;
|
|
902
|
+
var NO_GROUPS = [];
|
|
903
|
+
var TONE_RANK = { info: 1, warning: 2, danger: 3 };
|
|
904
|
+
function GraphCanvas({
|
|
905
|
+
label,
|
|
906
|
+
bands,
|
|
907
|
+
nodes,
|
|
908
|
+
edges,
|
|
909
|
+
groups = NO_GROUPS,
|
|
910
|
+
collapseAbove,
|
|
911
|
+
openGroups,
|
|
912
|
+
onOpenGroupsChange,
|
|
913
|
+
selectedId = null,
|
|
914
|
+
onSelect,
|
|
915
|
+
trace = null,
|
|
916
|
+
cardDimmed,
|
|
917
|
+
overlay,
|
|
918
|
+
controlsPlacement,
|
|
919
|
+
controlsExtra,
|
|
920
|
+
controlsBelow,
|
|
921
|
+
controlsStart,
|
|
922
|
+
overlayEnd,
|
|
923
|
+
hint,
|
|
924
|
+
ground,
|
|
925
|
+
labels,
|
|
926
|
+
minZoom = GRAPH_CANVAS_FIT_FLOOR,
|
|
927
|
+
fitKey,
|
|
928
|
+
initialView,
|
|
929
|
+
onViewChange,
|
|
930
|
+
ref,
|
|
931
|
+
className
|
|
932
|
+
}) {
|
|
933
|
+
const text = useMemo(() => ({ ...GRAPH_CANVAS_LABELS, ...labels }), [labels]);
|
|
934
|
+
const uid = useId();
|
|
935
|
+
const nodeById = useMemo(() => new Map(nodes.map((node) => [node.id, node])), [nodes]);
|
|
936
|
+
const groupById = useMemo(() => new Map(groups.map((group) => [group.id, group])), [groups]);
|
|
937
|
+
const restEdges = useMemo(() => edges.filter((edge) => edge.atRest !== false), [edges]);
|
|
938
|
+
const groupOf = useCallback((id) => nodeById.get(id)?.group, [nodeById]);
|
|
939
|
+
const [toggled, setToggled] = useState(() => /* @__PURE__ */ new Map());
|
|
940
|
+
const startClosed = collapseAbove !== void 0 && nodes.length > collapseAbove;
|
|
941
|
+
const openSet = useMemo(() => {
|
|
942
|
+
if (openGroups) return openGroups;
|
|
943
|
+
const out = /* @__PURE__ */ new Set();
|
|
944
|
+
for (const group of groups) if (toggled.get(group.id) ?? !startClosed) out.add(group.id);
|
|
945
|
+
return out;
|
|
946
|
+
}, [openGroups, groups, toggled, startClosed]);
|
|
947
|
+
const setGroupOpen = useCallback(
|
|
948
|
+
(id, open) => {
|
|
949
|
+
if (openSet.has(id) === open) return;
|
|
950
|
+
const next = new Set(openSet);
|
|
951
|
+
if (open) next.add(id);
|
|
952
|
+
else next.delete(id);
|
|
953
|
+
if (!openGroups) setToggled((was) => new Map(was).set(id, open));
|
|
954
|
+
onOpenGroupsChange?.(next);
|
|
955
|
+
},
|
|
956
|
+
[openSet, openGroups, onOpenGroupsChange]
|
|
957
|
+
);
|
|
958
|
+
const { measure, sizes, measured } = useMeasuredSizes();
|
|
959
|
+
const metrics = useMemo(() => {
|
|
960
|
+
if (!measured(PROBES)) return null;
|
|
961
|
+
const card = sizes.get(CARD_PROBE);
|
|
962
|
+
const gap = sizes.get(GAP_PROBE);
|
|
963
|
+
const pad = sizes.get(PAD_PROBE);
|
|
964
|
+
return {
|
|
965
|
+
cardWidth: card.width,
|
|
966
|
+
cardHeight: card.height,
|
|
967
|
+
gutter: gap.width,
|
|
968
|
+
rowGap: gap.height,
|
|
969
|
+
laneHead: sizes.get(HEAD_PROBE).height,
|
|
970
|
+
bandHead: sizes.get(BAND_PROBE).height,
|
|
971
|
+
bandGap: pad.height,
|
|
972
|
+
lanePad: pad.width,
|
|
973
|
+
margin: pad.height
|
|
974
|
+
};
|
|
975
|
+
}, [measured, sizes]);
|
|
976
|
+
const emptyLanes = useMemo(() => {
|
|
977
|
+
const filled = new Set(nodes.map((node) => node.lane));
|
|
978
|
+
return bands.flatMap((band) => band.lanes.filter((lane) => !filled.has(lane.id)));
|
|
979
|
+
}, [bands, nodes]);
|
|
980
|
+
const emptyHeights = useMemo(() => {
|
|
981
|
+
const out = /* @__PURE__ */ new Map();
|
|
982
|
+
for (const lane of emptyLanes) {
|
|
983
|
+
const size = sizes.get(emptyProbe(lane.id));
|
|
984
|
+
if (size) out.set(lane.id, size.height);
|
|
985
|
+
}
|
|
986
|
+
return out;
|
|
987
|
+
}, [emptyLanes, sizes]);
|
|
988
|
+
const layoutBands = useMemo(
|
|
989
|
+
() => bands.map((band) => ({ id: band.id, titled: Boolean(band.label), lanes: band.lanes.map((lane) => lane.id) })),
|
|
990
|
+
[bands]
|
|
991
|
+
);
|
|
992
|
+
const layout = useMemo(() => {
|
|
993
|
+
if (!metrics) return null;
|
|
994
|
+
return layoutGraph(
|
|
995
|
+
{ bands: layoutBands, nodes, groups, open: (id) => openSet.has(id), edges: restEdges, emptyHeights },
|
|
996
|
+
metrics
|
|
997
|
+
);
|
|
998
|
+
}, [metrics, layoutBands, nodes, groups, openSet, restEdges, emptyHeights]);
|
|
999
|
+
const everPlaced = useRef(false);
|
|
1000
|
+
const placed = layout !== null && (everPlaced.current || measured(emptyLanes.map((lane) => emptyProbe(lane.id))));
|
|
1001
|
+
if (placed) everPlaced.current = true;
|
|
1002
|
+
const laneOf = useMemo(() => new Map(bands.flatMap((band) => band.lanes.map((lane) => [lane.id, lane]))), [bands]);
|
|
1003
|
+
const reach = useMemo(() => {
|
|
1004
|
+
if (selectedId === null || !nodeById.has(selectedId)) return null;
|
|
1005
|
+
return trace ? graphReach(edges, selectedId, trace.direction, trace.depth) : graphNeighbourhood(edges, selectedId);
|
|
1006
|
+
}, [selectedId, nodeById, trace, edges]);
|
|
1007
|
+
const nodeDimmed = useCallback(
|
|
1008
|
+
(id) => Boolean(cardDimmed?.(id)) || reach !== null && !reach.nodes.has(id),
|
|
1009
|
+
[cardDimmed, reach]
|
|
1010
|
+
);
|
|
1011
|
+
const selectedGroup = selectedId === null ? void 0 : groupOf(selectedId);
|
|
1012
|
+
const anchorNext = useRef(null);
|
|
1013
|
+
const openedFor = useRef(null);
|
|
1014
|
+
useLayoutEffect(() => {
|
|
1015
|
+
if (!layout || selectedId === openedFor.current) return;
|
|
1016
|
+
openedFor.current = selectedId;
|
|
1017
|
+
if (selectedId === null || selectedGroup === void 0 || openSet.has(selectedGroup)) return;
|
|
1018
|
+
const summary = layout.itemByKey.get(graphItemKey("summary", selectedGroup));
|
|
1019
|
+
if (summary) anchorNext.current = { key: graphItemKey("node", selectedId), before: summary };
|
|
1020
|
+
setGroupOpen(selectedGroup, true);
|
|
1021
|
+
}, [selectedGroup, selectedId, openSet, layout, setGroupOpen]);
|
|
1022
|
+
const drawn = useMemo(() => {
|
|
1023
|
+
if (!layout) return null;
|
|
1024
|
+
const lit = /* @__PURE__ */ new Set();
|
|
1025
|
+
const extra = [];
|
|
1026
|
+
const known = new Set(layout.routes.map((route) => route.key));
|
|
1027
|
+
if (reach) {
|
|
1028
|
+
for (const edge of edges) {
|
|
1029
|
+
if (!reach.edges.has(edge.id)) continue;
|
|
1030
|
+
const route = layout.routeOfEdge.get(edge.id);
|
|
1031
|
+
if (route !== void 0) {
|
|
1032
|
+
lit.add(route);
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
const from = layout.itemOfNode.get(edge.from);
|
|
1036
|
+
const to = layout.itemOfNode.get(edge.to);
|
|
1037
|
+
if (from === void 0 || to === void 0 || from === to) continue;
|
|
1038
|
+
if (known.has(`${from}>${to}`)) lit.add(`${from}>${to}`);
|
|
1039
|
+
else extra.push(edge);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
const itemDimmed = (key) => {
|
|
1043
|
+
const item = layout.itemByKey.get(key);
|
|
1044
|
+
if (item.kind === "node") return nodeDimmed(item.id);
|
|
1045
|
+
return layout.groupById.get(item.id)?.members.every(nodeDimmed) ?? false;
|
|
1046
|
+
};
|
|
1047
|
+
const quiet = [];
|
|
1048
|
+
const faint = [];
|
|
1049
|
+
const strong = [];
|
|
1050
|
+
for (const route of layout.routes) {
|
|
1051
|
+
if (lit.has(route.key)) strong.push(route);
|
|
1052
|
+
else if (reach || itemDimmed(route.from) || itemDimmed(route.to)) faint.push(route);
|
|
1053
|
+
else quiet.push(route);
|
|
1054
|
+
}
|
|
1055
|
+
strong.push(...routeGraphEdges(layout, extra));
|
|
1056
|
+
return { quiet, faint, strong, itemDimmed };
|
|
1057
|
+
}, [layout, reach, edges, nodeDimmed]);
|
|
1058
|
+
const relationsOf = useMemo(() => {
|
|
1059
|
+
const out = /* @__PURE__ */ new Map();
|
|
1060
|
+
const entry = (id) => {
|
|
1061
|
+
let one = out.get(id);
|
|
1062
|
+
if (!one) out.set(id, one = { dependsOn: [], usedBy: [] });
|
|
1063
|
+
return one;
|
|
1064
|
+
};
|
|
1065
|
+
for (const edge of edges) {
|
|
1066
|
+
const from = nodeById.get(edge.from);
|
|
1067
|
+
const to = nodeById.get(edge.to);
|
|
1068
|
+
if (!from || !to || from === to) continue;
|
|
1069
|
+
entry(from.id).dependsOn.push({ relation: edge.label, name: to.name });
|
|
1070
|
+
entry(to.id).usedBy.push({ relation: edge.label, name: from.name });
|
|
1071
|
+
}
|
|
1072
|
+
return out;
|
|
1073
|
+
}, [edges, nodeById]);
|
|
1074
|
+
const canvas = useRef(null);
|
|
1075
|
+
const [mounted, setMounted] = useState(null);
|
|
1076
|
+
const mountedNow = useRef(mounted);
|
|
1077
|
+
mountedNow.current = mounted;
|
|
1078
|
+
const viewChanged = useCallback(
|
|
1079
|
+
(view, viewport) => {
|
|
1080
|
+
onViewChange?.(view, viewport);
|
|
1081
|
+
const next = graphWindow(mountedNow.current, view, viewport);
|
|
1082
|
+
if (next !== mountedNow.current) setMounted(next);
|
|
1083
|
+
},
|
|
1084
|
+
[onViewChange]
|
|
1085
|
+
);
|
|
1086
|
+
const paths = useMemo(() => {
|
|
1087
|
+
if (!drawn) return null;
|
|
1088
|
+
const near = (route) => !mounted || intersects(route.box, mounted.rect);
|
|
1089
|
+
const join = (list, part, all = false) => list.filter((route) => all || near(route)).map((route) => route[part]).join("");
|
|
1090
|
+
return {
|
|
1091
|
+
quiet: { d: join(drawn.quiet, "d"), arrow: join(drawn.quiet, "arrow") },
|
|
1092
|
+
faint: { d: join(drawn.faint, "d"), arrow: join(drawn.faint, "arrow") },
|
|
1093
|
+
strong: { d: join(drawn.strong, "d", true), arrow: join(drawn.strong, "arrow", true) }
|
|
1094
|
+
};
|
|
1095
|
+
}, [drawn, mounted]);
|
|
1096
|
+
const root = useRef(null);
|
|
1097
|
+
const [frame, setFrame] = useState(null);
|
|
1098
|
+
useLayoutEffect(() => {
|
|
1099
|
+
const el = root.current;
|
|
1100
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
1101
|
+
const observer = new ResizeObserver((entries) => {
|
|
1102
|
+
const box = entries[entries.length - 1]?.contentRect;
|
|
1103
|
+
if (box && box.width > 0 && box.height > 0) setFrame((was) => was ?? { width: box.width, height: box.height });
|
|
1104
|
+
});
|
|
1105
|
+
observer.observe(el);
|
|
1106
|
+
return () => observer.disconnect();
|
|
1107
|
+
}, []);
|
|
1108
|
+
const [chrome, setChrome] = useState(0);
|
|
1109
|
+
useLayoutEffect(() => {
|
|
1110
|
+
const el = root.current;
|
|
1111
|
+
if (!el || !frame) return;
|
|
1112
|
+
const top = el.getBoundingClientRect().top;
|
|
1113
|
+
let bottom = 0;
|
|
1114
|
+
for (const bar of el.querySelectorAll(".crewlet-canvas__controls")) {
|
|
1115
|
+
const rect = bar.getBoundingClientRect();
|
|
1116
|
+
if (rect.height > 0 && rect.top - top < frame.height / 2) bottom = Math.max(bottom, rect.bottom - top);
|
|
1117
|
+
}
|
|
1118
|
+
setChrome(bottom);
|
|
1119
|
+
}, [frame, controlsStart, controlsPlacement]);
|
|
1120
|
+
const opening = useMemo(() => {
|
|
1121
|
+
if (initialView) return initialView;
|
|
1122
|
+
if (!layout || !frame) return void 0;
|
|
1123
|
+
const fit = fitView(layout.bounds, frame, CANVAS_FIT_PADDING, minZoom);
|
|
1124
|
+
if (fit.k >= GRAPH_CANVAS_DETAIL_ZOOM) return void 0;
|
|
1125
|
+
const k = GRAPH_CANVAS_OPEN_ZOOM;
|
|
1126
|
+
const y = Math.max(CANVAS_FIT_PADDING, chrome + CANVAS_FIT_PADDING / 2);
|
|
1127
|
+
return { k, x: CANVAS_FIT_PADDING - layout.bounds.x * k, y: y - layout.bounds.y * k };
|
|
1128
|
+
}, [initialView, layout, frame, minZoom, chrome]);
|
|
1129
|
+
const [active, setActive] = useState(null);
|
|
1130
|
+
const selectedKey = selectedId === null || !layout ? null : layout.itemOfNode.get(selectedId) ?? null;
|
|
1131
|
+
const activeKey = active !== null && layout?.itemByKey.has(active) ? active : selectedKey ?? layout?.lanes.find((lane) => lane.items.length > 0)?.items[0] ?? null;
|
|
1132
|
+
const elements = useRef(/* @__PURE__ */ new Map());
|
|
1133
|
+
const refs = useRef(/* @__PURE__ */ new Map());
|
|
1134
|
+
const refFor = useCallback((key) => {
|
|
1135
|
+
let callback = refs.current.get(key);
|
|
1136
|
+
if (!callback) {
|
|
1137
|
+
callback = (el) => {
|
|
1138
|
+
if (el) elements.current.set(key, el);
|
|
1139
|
+
else if (elements.current.get(key)?.isConnected === false) elements.current.delete(key);
|
|
1140
|
+
};
|
|
1141
|
+
refs.current.set(key, callback);
|
|
1142
|
+
}
|
|
1143
|
+
return callback;
|
|
1144
|
+
}, []);
|
|
1145
|
+
const pendingFocus = useRef(null);
|
|
1146
|
+
const focusNow = useCallback(
|
|
1147
|
+
(key) => {
|
|
1148
|
+
const el = elements.current.get(key);
|
|
1149
|
+
const item = layout?.itemByKey.get(key);
|
|
1150
|
+
if (!el || !el.isConnected || !item) return false;
|
|
1151
|
+
el.focus({ preventScroll: true });
|
|
1152
|
+
canvas.current?.reveal(item);
|
|
1153
|
+
return true;
|
|
1154
|
+
},
|
|
1155
|
+
[layout]
|
|
1156
|
+
);
|
|
1157
|
+
const focusItem = useCallback((key) => {
|
|
1158
|
+
setActive(key);
|
|
1159
|
+
pendingFocus.current = key;
|
|
1160
|
+
}, []);
|
|
1161
|
+
useLayoutEffect(() => {
|
|
1162
|
+
const key = pendingFocus.current;
|
|
1163
|
+
if (key !== null && focusNow(key)) pendingFocus.current = null;
|
|
1164
|
+
});
|
|
1165
|
+
useLayoutEffect(() => {
|
|
1166
|
+
const pending = anchorNext.current;
|
|
1167
|
+
if (!pending || !layout) return;
|
|
1168
|
+
const after = layout.itemByKey.get(pending.key);
|
|
1169
|
+
if (!after) return;
|
|
1170
|
+
anchorNext.current = null;
|
|
1171
|
+
canvas.current?.anchor(pending.before, after);
|
|
1172
|
+
}, [layout]);
|
|
1173
|
+
const toggleGroup = useCallback(
|
|
1174
|
+
(id, focus) => {
|
|
1175
|
+
if (!layout) return;
|
|
1176
|
+
const open = openSet.has(id);
|
|
1177
|
+
const before = layout.itemByKey.get(graphItemKey(open ? "head" : "summary", id));
|
|
1178
|
+
const next = graphItemKey(open ? "summary" : "head", id);
|
|
1179
|
+
if (before) anchorNext.current = { key: next, before };
|
|
1180
|
+
setGroupOpen(id, !open);
|
|
1181
|
+
setActive(next);
|
|
1182
|
+
if (focus) pendingFocus.current = next;
|
|
1183
|
+
},
|
|
1184
|
+
[layout, openSet, setGroupOpen]
|
|
1185
|
+
);
|
|
1186
|
+
const layoutNow = useRef(layout);
|
|
1187
|
+
layoutNow.current = layout;
|
|
1188
|
+
const openNow = useRef({ openSet, groupOf, setGroupOpen });
|
|
1189
|
+
openNow.current = { openSet, groupOf, setGroupOpen };
|
|
1190
|
+
useImperativeHandle(
|
|
1191
|
+
ref,
|
|
1192
|
+
() => ({
|
|
1193
|
+
focusNode: (id) => {
|
|
1194
|
+
const { openSet: shown, groupOf: owner, setGroupOpen: reveal } = openNow.current;
|
|
1195
|
+
const group = owner(id);
|
|
1196
|
+
if (group !== void 0 && !shown.has(group)) reveal(group, true);
|
|
1197
|
+
focusItem(graphItemKey("node", id));
|
|
1198
|
+
},
|
|
1199
|
+
fit: () => canvas.current?.fit()
|
|
1200
|
+
}),
|
|
1201
|
+
[focusItem]
|
|
1202
|
+
);
|
|
1203
|
+
const fittedFor = useRef(fitKey);
|
|
1204
|
+
const placedOnce = useRef(false);
|
|
1205
|
+
useLayoutEffect(() => {
|
|
1206
|
+
if (!placed) return;
|
|
1207
|
+
if (!placedOnce.current) {
|
|
1208
|
+
placedOnce.current = true;
|
|
1209
|
+
fittedFor.current = fitKey;
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
if (fitKey === fittedFor.current) return;
|
|
1213
|
+
fittedFor.current = fitKey;
|
|
1214
|
+
canvas.current?.fit();
|
|
1215
|
+
}, [fitKey, placed]);
|
|
1216
|
+
const typed = useRef({ text: "", at: 0 });
|
|
1217
|
+
const activate = useCallback(
|
|
1218
|
+
(item, focus) => {
|
|
1219
|
+
if (item.kind === "node") {
|
|
1220
|
+
onSelect?.(item.id);
|
|
1221
|
+
setActive(item.key);
|
|
1222
|
+
if (focus) pendingFocus.current = item.key;
|
|
1223
|
+
} else if (item.kind === "head" || item.kind === "summary") {
|
|
1224
|
+
toggleGroup(item.id, focus);
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1227
|
+
[onSelect, toggleGroup]
|
|
1228
|
+
);
|
|
1229
|
+
function onKeyDown(event) {
|
|
1230
|
+
if (!layout) return;
|
|
1231
|
+
if (event.key === "Escape") {
|
|
1232
|
+
if (selectedId === null) return;
|
|
1233
|
+
event.preventDefault();
|
|
1234
|
+
event.stopPropagation();
|
|
1235
|
+
onSelect?.(null);
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
if (event.target !== event.currentTarget) return;
|
|
1239
|
+
const key = event.currentTarget.getAttribute("data-graph-key");
|
|
1240
|
+
if (key === null) return;
|
|
1241
|
+
const item = layout.itemByKey.get(key);
|
|
1242
|
+
if (!item) return;
|
|
1243
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1244
|
+
event.preventDefault();
|
|
1245
|
+
activate(item, true);
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
const step = graphStep(layout, key, event);
|
|
1249
|
+
if (step !== void 0) {
|
|
1250
|
+
event.preventDefault();
|
|
1251
|
+
if (step !== null) focusItem(step);
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
const now = Date.now();
|
|
1255
|
+
if (isTypeAheadKey(event, typed.current, now)) {
|
|
1256
|
+
typed.current = typeAheadBuffer(typed.current, event.key, now);
|
|
1257
|
+
const found = typeAhead(layout, key, typed.current.text, (one) => nameOf(one));
|
|
1258
|
+
if (found !== null) {
|
|
1259
|
+
event.preventDefault();
|
|
1260
|
+
focusItem(found);
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
const handlers = useRef({ onKeyDown, activate, setActive, layout });
|
|
1265
|
+
handlers.current = { onKeyDown, activate, setActive, layout };
|
|
1266
|
+
const onItemKey = useCallback((event) => handlers.current.onKeyDown(event), []);
|
|
1267
|
+
const onItemPress = useCallback((key) => {
|
|
1268
|
+
const item = handlers.current.layout?.itemByKey.get(key);
|
|
1269
|
+
if (item) handlers.current.activate(item, true);
|
|
1270
|
+
}, []);
|
|
1271
|
+
const onItemFocus = useCallback((key) => handlers.current.setActive(key), []);
|
|
1272
|
+
const nameOf = (item) => {
|
|
1273
|
+
if (item.kind === "node") return nodeById.get(item.id)?.name ?? "";
|
|
1274
|
+
if (item.kind === "empty") return laneOf.get(item.id)?.label ?? "";
|
|
1275
|
+
return groupById.get(item.id)?.label ?? "";
|
|
1276
|
+
};
|
|
1277
|
+
const shownItems = useMemo(() => {
|
|
1278
|
+
if (!layout || !mounted) return [];
|
|
1279
|
+
const keep = /* @__PURE__ */ new Set();
|
|
1280
|
+
if (activeKey !== null) keep.add(activeKey);
|
|
1281
|
+
if (selectedKey !== null) keep.add(selectedKey);
|
|
1282
|
+
return layout.items.filter((item) => {
|
|
1283
|
+
if (keep.has(item.key)) return true;
|
|
1284
|
+
if (!mounted.detail && item.kind !== "empty" && item.kind !== "head") return false;
|
|
1285
|
+
return intersects(item, mounted.rect);
|
|
1286
|
+
});
|
|
1287
|
+
}, [layout, mounted, activeKey, selectedKey]);
|
|
1288
|
+
const shownByLane = useMemo(() => {
|
|
1289
|
+
const out = /* @__PURE__ */ new Map();
|
|
1290
|
+
for (const item of shownItems) {
|
|
1291
|
+
let list = out.get(item.lane);
|
|
1292
|
+
if (!list) out.set(item.lane, list = []);
|
|
1293
|
+
list.push(item);
|
|
1294
|
+
}
|
|
1295
|
+
return out;
|
|
1296
|
+
}, [shownItems]);
|
|
1297
|
+
const worstOf = useCallback(
|
|
1298
|
+
(members) => {
|
|
1299
|
+
let worst;
|
|
1300
|
+
for (const id of members) {
|
|
1301
|
+
const attention = nodeById.get(id)?.attention;
|
|
1302
|
+
if (attention && (!worst || TONE_RANK[attention.tone] > TONE_RANK[worst.tone])) worst = attention;
|
|
1303
|
+
}
|
|
1304
|
+
return worst;
|
|
1305
|
+
},
|
|
1306
|
+
[nodeById]
|
|
1307
|
+
);
|
|
1308
|
+
const renderItem = (item) => {
|
|
1309
|
+
const common = {
|
|
1310
|
+
itemKey: item.key,
|
|
1311
|
+
item,
|
|
1312
|
+
tabIndex: item.key === activeKey ? 0 : -1,
|
|
1313
|
+
refFor,
|
|
1314
|
+
onPress: onItemPress,
|
|
1315
|
+
onFocusItem: onItemFocus,
|
|
1316
|
+
onItemKey
|
|
1317
|
+
};
|
|
1318
|
+
if (item.kind === "node") {
|
|
1319
|
+
const node = nodeById.get(item.id);
|
|
1320
|
+
const relations = relationsOf.get(item.id);
|
|
1321
|
+
return /* @__PURE__ */ jsx(
|
|
1322
|
+
GraphCard,
|
|
1323
|
+
{
|
|
1324
|
+
...common,
|
|
1325
|
+
node,
|
|
1326
|
+
selected: item.id === selectedId,
|
|
1327
|
+
dimmed: nodeDimmed(item.id),
|
|
1328
|
+
description: relations ? text.relations(relations.dependsOn, relations.usedBy) : "",
|
|
1329
|
+
descriptionId: `${uid}-d-${encodeURIComponent(item.key)}`,
|
|
1330
|
+
unconfirmedLabel: text.unconfirmed
|
|
1331
|
+
},
|
|
1332
|
+
item.key
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
if (item.kind === "summary" || item.kind === "head") {
|
|
1336
|
+
const group = groupById.get(item.id);
|
|
1337
|
+
const members = layout?.groupById.get(item.id)?.members ?? [];
|
|
1338
|
+
return /* @__PURE__ */ jsx(
|
|
1339
|
+
GraphGroupItem,
|
|
1340
|
+
{
|
|
1341
|
+
...common,
|
|
1342
|
+
label: group?.label ?? item.id,
|
|
1343
|
+
lead: group?.lead,
|
|
1344
|
+
count: members.length,
|
|
1345
|
+
attention: item.kind === "summary" ? worstOf(members) : void 0,
|
|
1346
|
+
dimmed: drawn?.itemDimmed(item.key) ?? false,
|
|
1347
|
+
selected: item.key === selectedKey,
|
|
1348
|
+
text
|
|
1349
|
+
},
|
|
1350
|
+
item.key
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
const lane = laneOf.get(item.id);
|
|
1354
|
+
return /* @__PURE__ */ jsx(GraphEmptyLane, { ...common, label: text.emptyLane(lane?.label ?? item.id), children: lane?.empty }, item.key);
|
|
1355
|
+
};
|
|
1356
|
+
const width = layout?.bounds.width ?? 0;
|
|
1357
|
+
const height = layout?.bounds.height ?? 0;
|
|
1358
|
+
return /* @__PURE__ */ jsx("div", { ref: root, className: cx("crewlet-graph-canvas", className), children: frame ? /* @__PURE__ */ jsxs(
|
|
1359
|
+
Canvas,
|
|
1360
|
+
{
|
|
1361
|
+
label,
|
|
1362
|
+
content: placed ? layout.bounds : null,
|
|
1363
|
+
ref: canvas,
|
|
1364
|
+
overlay,
|
|
1365
|
+
controlsPlacement,
|
|
1366
|
+
controlsExtra,
|
|
1367
|
+
controlsBelow,
|
|
1368
|
+
controlsStart,
|
|
1369
|
+
overlayEnd,
|
|
1370
|
+
hint,
|
|
1371
|
+
ground,
|
|
1372
|
+
largestItemWidth: metrics?.cardWidth,
|
|
1373
|
+
labels: text,
|
|
1374
|
+
minZoom,
|
|
1375
|
+
initialView: opening,
|
|
1376
|
+
onViewChange: viewChanged,
|
|
1377
|
+
children: [
|
|
1378
|
+
/* @__PURE__ */ jsx(Probes, { measure }),
|
|
1379
|
+
emptyLanes.map((lane) => {
|
|
1380
|
+
const placedLane = layout?.laneById.get(lane.id);
|
|
1381
|
+
return /* @__PURE__ */ jsx(
|
|
1382
|
+
"div",
|
|
1383
|
+
{
|
|
1384
|
+
ref: measure(emptyProbe(lane.id)),
|
|
1385
|
+
className: "crewlet-graph-canvas__empty-probe",
|
|
1386
|
+
"aria-hidden": "true",
|
|
1387
|
+
inert: true,
|
|
1388
|
+
style: placedLane ? { width: `${placedLane.head.width}px` } : void 0,
|
|
1389
|
+
children: lane.empty
|
|
1390
|
+
},
|
|
1391
|
+
lane.id
|
|
1392
|
+
);
|
|
1393
|
+
}),
|
|
1394
|
+
layout && placed ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1395
|
+
/* @__PURE__ */ jsxs("svg", { className: "crewlet-graph-canvas__ground", width, height, "aria-hidden": "true", children: [
|
|
1396
|
+
layout.lanes.map((lane) => /* @__PURE__ */ jsx(
|
|
1397
|
+
"rect",
|
|
1398
|
+
{
|
|
1399
|
+
className: "crewlet-graph-canvas__lane",
|
|
1400
|
+
x: lane.panel.x,
|
|
1401
|
+
y: lane.panel.y,
|
|
1402
|
+
width: lane.panel.width,
|
|
1403
|
+
height: lane.panel.height
|
|
1404
|
+
},
|
|
1405
|
+
lane.id
|
|
1406
|
+
)),
|
|
1407
|
+
layout.groups.map(
|
|
1408
|
+
(group) => group.box ? /* @__PURE__ */ jsx(
|
|
1409
|
+
"rect",
|
|
1410
|
+
{
|
|
1411
|
+
className: "crewlet-graph-canvas__group",
|
|
1412
|
+
x: group.box.x,
|
|
1413
|
+
y: group.box.y,
|
|
1414
|
+
width: group.box.width,
|
|
1415
|
+
height: group.box.height
|
|
1416
|
+
},
|
|
1417
|
+
group.id
|
|
1418
|
+
) : null
|
|
1419
|
+
)
|
|
1420
|
+
] }),
|
|
1421
|
+
layout.bands.map(
|
|
1422
|
+
(band) => band.title ? /* @__PURE__ */ jsx(
|
|
1423
|
+
"div",
|
|
1424
|
+
{
|
|
1425
|
+
className: "crewlet-graph-canvas__band-title",
|
|
1426
|
+
"aria-hidden": "true",
|
|
1427
|
+
style: placedStyle(band.title),
|
|
1428
|
+
children: bands[band.index].label
|
|
1429
|
+
},
|
|
1430
|
+
band.id
|
|
1431
|
+
) : null
|
|
1432
|
+
),
|
|
1433
|
+
layout.lanes.map((lane) => /* @__PURE__ */ jsxs(
|
|
1434
|
+
"div",
|
|
1435
|
+
{
|
|
1436
|
+
className: "crewlet-graph-canvas__lane-head",
|
|
1437
|
+
"aria-hidden": "true",
|
|
1438
|
+
style: placedStyle(lane.head),
|
|
1439
|
+
children: [
|
|
1440
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-label", children: laneOf.get(lane.id)?.label }),
|
|
1441
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-count", children: lane.count })
|
|
1442
|
+
]
|
|
1443
|
+
},
|
|
1444
|
+
lane.id
|
|
1445
|
+
)),
|
|
1446
|
+
paths ? /* @__PURE__ */ jsxs("svg", { className: "crewlet-graph-canvas__edges", width, height, "aria-hidden": "true", children: [
|
|
1447
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__edge", "data-state": "faint", d: paths.faint.d }),
|
|
1448
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__arrow", "data-state": "faint", d: paths.faint.arrow }),
|
|
1449
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__edge", "data-state": "quiet", d: paths.quiet.d }),
|
|
1450
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__arrow", "data-state": "quiet", d: paths.quiet.arrow }),
|
|
1451
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__edge", "data-state": "strong", d: paths.strong.d }),
|
|
1452
|
+
/* @__PURE__ */ jsx("path", { className: "crewlet-graph-canvas__arrow", "data-state": "strong", d: paths.strong.arrow })
|
|
1453
|
+
] }) : null,
|
|
1454
|
+
mounted && !mounted.detail ? /* @__PURE__ */ jsx(
|
|
1455
|
+
Shapes,
|
|
1456
|
+
{
|
|
1457
|
+
layout,
|
|
1458
|
+
nodeById,
|
|
1459
|
+
dimmed: drawn?.itemDimmed,
|
|
1460
|
+
worstOf,
|
|
1461
|
+
selectedKey
|
|
1462
|
+
}
|
|
1463
|
+
) : null,
|
|
1464
|
+
/* @__PURE__ */ jsx("div", { className: "crewlet-graph-canvas__items", children: bands.map((band, b) => {
|
|
1465
|
+
const lanes = layout.lanes.filter((lane) => lane.band === b);
|
|
1466
|
+
const body = lanes.map((lane) => /* @__PURE__ */ jsx(
|
|
1467
|
+
"div",
|
|
1468
|
+
{
|
|
1469
|
+
role: "group",
|
|
1470
|
+
"aria-label": text.lane(laneOf.get(lane.id)?.label ?? lane.id, lane.count),
|
|
1471
|
+
children: (shownByLane.get(lane.id) ?? []).map(renderItem)
|
|
1472
|
+
},
|
|
1473
|
+
lane.id
|
|
1474
|
+
));
|
|
1475
|
+
return band.label ? /* @__PURE__ */ jsx("div", { role: "group", "aria-label": band.label, children: body }, band.id) : /* @__PURE__ */ jsx("div", { role: "none", children: body }, band.id);
|
|
1476
|
+
}) })
|
|
1477
|
+
] }) : null
|
|
1478
|
+
]
|
|
1479
|
+
}
|
|
1480
|
+
) : null });
|
|
1481
|
+
}
|
|
1482
|
+
function Probes({ measure }) {
|
|
1483
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1484
|
+
/* @__PURE__ */ jsx(
|
|
1485
|
+
"div",
|
|
1486
|
+
{
|
|
1487
|
+
ref: measure(CARD_PROBE),
|
|
1488
|
+
className: "crewlet-graph-canvas__card crewlet-graph-canvas__probe",
|
|
1489
|
+
"aria-hidden": "true"
|
|
1490
|
+
}
|
|
1491
|
+
),
|
|
1492
|
+
/* @__PURE__ */ jsx(
|
|
1493
|
+
"div",
|
|
1494
|
+
{
|
|
1495
|
+
ref: measure(GAP_PROBE),
|
|
1496
|
+
className: "crewlet-graph-canvas__gap crewlet-graph-canvas__probe",
|
|
1497
|
+
"aria-hidden": "true"
|
|
1498
|
+
}
|
|
1499
|
+
),
|
|
1500
|
+
/* @__PURE__ */ jsx(
|
|
1501
|
+
"div",
|
|
1502
|
+
{
|
|
1503
|
+
ref: measure(PAD_PROBE),
|
|
1504
|
+
className: "crewlet-graph-canvas__pad crewlet-graph-canvas__probe",
|
|
1505
|
+
"aria-hidden": "true"
|
|
1506
|
+
}
|
|
1507
|
+
),
|
|
1508
|
+
/* @__PURE__ */ jsx(
|
|
1509
|
+
"div",
|
|
1510
|
+
{
|
|
1511
|
+
ref: measure(HEAD_PROBE),
|
|
1512
|
+
className: "crewlet-graph-canvas__lane-head crewlet-graph-canvas__probe",
|
|
1513
|
+
"aria-hidden": "true",
|
|
1514
|
+
children: /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lane-label", children: "M" })
|
|
1515
|
+
}
|
|
1516
|
+
),
|
|
1517
|
+
/* @__PURE__ */ jsx(
|
|
1518
|
+
"div",
|
|
1519
|
+
{
|
|
1520
|
+
ref: measure(BAND_PROBE),
|
|
1521
|
+
className: "crewlet-graph-canvas__band-title crewlet-graph-canvas__probe",
|
|
1522
|
+
"aria-hidden": "true",
|
|
1523
|
+
children: "M"
|
|
1524
|
+
}
|
|
1525
|
+
)
|
|
1526
|
+
] });
|
|
1527
|
+
}
|
|
1528
|
+
var GraphCard = memo(function GraphCard2({
|
|
1529
|
+
itemKey,
|
|
1530
|
+
item,
|
|
1531
|
+
tabIndex,
|
|
1532
|
+
refFor,
|
|
1533
|
+
onPress,
|
|
1534
|
+
onFocusItem,
|
|
1535
|
+
onItemKey,
|
|
1536
|
+
node,
|
|
1537
|
+
selected,
|
|
1538
|
+
dimmed,
|
|
1539
|
+
description,
|
|
1540
|
+
descriptionId,
|
|
1541
|
+
unconfirmedLabel
|
|
1542
|
+
}) {
|
|
1543
|
+
const spoken = [
|
|
1544
|
+
node.name,
|
|
1545
|
+
node.kind,
|
|
1546
|
+
node.caption,
|
|
1547
|
+
node.attention?.label,
|
|
1548
|
+
node.unconfirmed ? unconfirmedLabel : void 0
|
|
1549
|
+
].filter((part) => part !== void 0 && part !== "").join(", ");
|
|
1550
|
+
return /* @__PURE__ */ jsxs(
|
|
1551
|
+
"div",
|
|
1552
|
+
{
|
|
1553
|
+
ref: refFor(itemKey),
|
|
1554
|
+
role: "button",
|
|
1555
|
+
tabIndex,
|
|
1556
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
1557
|
+
"aria-current": selected ? "true" : void 0,
|
|
1558
|
+
"data-graph-key": itemKey,
|
|
1559
|
+
"data-attention": node.attention?.tone,
|
|
1560
|
+
"data-unconfirmed": node.unconfirmed ? "" : void 0,
|
|
1561
|
+
"data-selected": selected ? "" : void 0,
|
|
1562
|
+
"data-dimmed": dimmed ? "" : void 0,
|
|
1563
|
+
className: "crewlet-graph-canvas__card",
|
|
1564
|
+
style: { transform: `translate(${item.x}px, ${item.y}px)` },
|
|
1565
|
+
onClick: () => onPress(itemKey),
|
|
1566
|
+
onFocus: () => onFocusItem(itemKey),
|
|
1567
|
+
onKeyDown: onItemKey,
|
|
1568
|
+
children: [
|
|
1569
|
+
/* @__PURE__ */ jsx(IconTile, { size: "sm", tone: "neutral", className: "crewlet-graph-canvas__tile", children: node.glyph }),
|
|
1570
|
+
/* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__text", "aria-hidden": "true", children: [
|
|
1571
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__name", children: node.name }),
|
|
1572
|
+
node.caption ? /* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__caption", children: node.caption }) : null
|
|
1573
|
+
] }),
|
|
1574
|
+
node.attention ? /* @__PURE__ */ jsx(StatusDot, { tone: node.attention.tone, className: "crewlet-graph-canvas__dot" }) : null,
|
|
1575
|
+
/* @__PURE__ */ jsx(SpokenName, { spoken, description, descriptionId })
|
|
1576
|
+
]
|
|
1577
|
+
}
|
|
1578
|
+
);
|
|
1579
|
+
});
|
|
1580
|
+
var GraphGroupItem = memo(function GraphGroupItem2({
|
|
1581
|
+
itemKey,
|
|
1582
|
+
item,
|
|
1583
|
+
tabIndex,
|
|
1584
|
+
refFor,
|
|
1585
|
+
onPress,
|
|
1586
|
+
onFocusItem,
|
|
1587
|
+
onItemKey,
|
|
1588
|
+
label,
|
|
1589
|
+
lead,
|
|
1590
|
+
count,
|
|
1591
|
+
attention,
|
|
1592
|
+
dimmed,
|
|
1593
|
+
selected,
|
|
1594
|
+
text
|
|
1595
|
+
}) {
|
|
1596
|
+
const open = item.kind === "head";
|
|
1597
|
+
const spoken = [open ? text.openGroup(label, count) : text.closedGroup(label, count), attention?.label].filter(Boolean).join(", ");
|
|
1598
|
+
return /* @__PURE__ */ jsx(
|
|
1599
|
+
"div",
|
|
1600
|
+
{
|
|
1601
|
+
ref: refFor(itemKey),
|
|
1602
|
+
role: "button",
|
|
1603
|
+
tabIndex,
|
|
1604
|
+
"aria-expanded": open,
|
|
1605
|
+
"data-graph-key": itemKey,
|
|
1606
|
+
"aria-current": selected ? "true" : void 0,
|
|
1607
|
+
"data-attention": attention?.tone,
|
|
1608
|
+
"data-dimmed": dimmed ? "" : void 0,
|
|
1609
|
+
"data-selected": selected ? "" : void 0,
|
|
1610
|
+
className: open ? "crewlet-graph-canvas__head" : "crewlet-graph-canvas__card crewlet-graph-canvas__card--group",
|
|
1611
|
+
style: {
|
|
1612
|
+
transform: `translate(${item.x}px, ${item.y}px)`,
|
|
1613
|
+
...open ? { width: `${item.width}px`, height: `${item.height}px` } : {}
|
|
1614
|
+
},
|
|
1615
|
+
onClick: () => onPress(itemKey),
|
|
1616
|
+
onFocus: () => onFocusItem(itemKey),
|
|
1617
|
+
onKeyDown: onItemKey,
|
|
1618
|
+
children: open ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1619
|
+
/* @__PURE__ */ jsx(ChevronDownGlyph, { size: "xs", "aria-hidden": "true", className: "crewlet-graph-canvas__chevron" }),
|
|
1620
|
+
lead ? /* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__lead", "aria-hidden": "true", children: lead }) : null,
|
|
1621
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__group-label", "aria-hidden": "true", children: label }),
|
|
1622
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-graph-canvas__group-count", "aria-hidden": "true", children: count }),
|
|
1623
|
+
/* @__PURE__ */ jsx(SpokenName, { spoken })
|
|
1624
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1625
|
+
/* @__PURE__ */ jsx(IconTile, { size: "sm", tone: "neutral", className: "crewlet-graph-canvas__tile", children: lead ?? /* @__PURE__ */ jsx(ChevronRightGlyph, { size: "sm" }) }),
|
|
1626
|
+
/* @__PURE__ */ jsxs("span", { className: "crewlet-graph-canvas__text", "aria-hidden": "true", children: [
|
|
1627
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__name", children: label }),
|
|
1628
|
+
/* @__PURE__ */ jsx(Text, { variant: "inherit", truncate: true, className: "crewlet-graph-canvas__caption", children: text.entries(count) })
|
|
1629
|
+
] }),
|
|
1630
|
+
/* @__PURE__ */ jsx(ChevronRightGlyph, { size: "xs", "aria-hidden": "true", className: "crewlet-graph-canvas__chevron" }),
|
|
1631
|
+
attention ? /* @__PURE__ */ jsx(StatusDot, { tone: attention.tone, className: "crewlet-graph-canvas__dot" }) : null,
|
|
1632
|
+
/* @__PURE__ */ jsx(SpokenName, { spoken })
|
|
1633
|
+
] })
|
|
1634
|
+
}
|
|
1635
|
+
);
|
|
1636
|
+
});
|
|
1637
|
+
function SpokenName({
|
|
1638
|
+
spoken,
|
|
1639
|
+
description,
|
|
1640
|
+
descriptionId
|
|
1641
|
+
}) {
|
|
1642
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1643
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: spoken }),
|
|
1644
|
+
description ? /* @__PURE__ */ jsx("span", { id: descriptionId, hidden: true, children: description }) : null
|
|
1645
|
+
] });
|
|
1646
|
+
}
|
|
1647
|
+
function GraphEmptyLane({
|
|
1648
|
+
itemKey,
|
|
1649
|
+
item,
|
|
1650
|
+
tabIndex,
|
|
1651
|
+
refFor,
|
|
1652
|
+
onFocusItem,
|
|
1653
|
+
onItemKey,
|
|
1654
|
+
label,
|
|
1655
|
+
children
|
|
1656
|
+
}) {
|
|
1657
|
+
return (
|
|
1658
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- see above
|
|
1659
|
+
/* @__PURE__ */ jsx(
|
|
1660
|
+
"div",
|
|
1661
|
+
{
|
|
1662
|
+
ref: refFor(itemKey),
|
|
1663
|
+
role: "group",
|
|
1664
|
+
tabIndex,
|
|
1665
|
+
"aria-label": label,
|
|
1666
|
+
"data-graph-key": itemKey,
|
|
1667
|
+
className: "crewlet-graph-canvas__empty",
|
|
1668
|
+
style: { transform: `translate(${item.x}px, ${item.y}px)`, width: `${item.width}px`, height: `${item.height}px` },
|
|
1669
|
+
onFocus: (event) => {
|
|
1670
|
+
if (event.target === event.currentTarget) onFocusItem(itemKey);
|
|
1671
|
+
},
|
|
1672
|
+
onKeyDown: onItemKey,
|
|
1673
|
+
children
|
|
1674
|
+
}
|
|
1675
|
+
)
|
|
1676
|
+
);
|
|
1677
|
+
}
|
|
1678
|
+
function Shapes({
|
|
1679
|
+
layout,
|
|
1680
|
+
nodeById,
|
|
1681
|
+
dimmed,
|
|
1682
|
+
worstOf,
|
|
1683
|
+
selectedKey
|
|
1684
|
+
}) {
|
|
1685
|
+
const paths = useMemo(() => {
|
|
1686
|
+
const out = { card: "", faded: "", dashed: "", danger: "", warning: "", info: "", selected: "" };
|
|
1687
|
+
const radius = Math.min(6, layout.metrics.cardHeight / 6);
|
|
1688
|
+
for (const item of layout.items) {
|
|
1689
|
+
if (item.kind !== "node" && item.kind !== "summary") continue;
|
|
1690
|
+
const node = item.kind === "node" ? nodeById.get(item.id) : void 0;
|
|
1691
|
+
const rect = roundRect(item, radius);
|
|
1692
|
+
if (item.key === selectedKey) out.selected += rect;
|
|
1693
|
+
else if (dimmed?.(item.key)) out.faded += rect;
|
|
1694
|
+
else if (node?.unconfirmed) out.dashed += rect;
|
|
1695
|
+
else out.card += rect;
|
|
1696
|
+
const attention = node ? node.attention : worstOf(layout.groupById.get(item.id)?.members ?? []);
|
|
1697
|
+
if (attention) {
|
|
1698
|
+
const r = layout.metrics.cardHeight / 8;
|
|
1699
|
+
const cx2 = item.x + item.width - r * 2;
|
|
1700
|
+
const cy = item.y + r * 2;
|
|
1701
|
+
out[attention.tone] += `M${cx2 - r} ${cy}a${r} ${r} 0 1 0 ${2 * r} 0a${r} ${r} 0 1 0 ${ -2 * r} 0Z`;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return out;
|
|
1705
|
+
}, [layout, nodeById, dimmed, worstOf, selectedKey]);
|
|
1706
|
+
return /* @__PURE__ */ jsxs(
|
|
1707
|
+
"svg",
|
|
1708
|
+
{
|
|
1709
|
+
className: "crewlet-graph-canvas__shapes",
|
|
1710
|
+
width: layout.bounds.width,
|
|
1711
|
+
height: layout.bounds.height,
|
|
1712
|
+
"aria-hidden": "true",
|
|
1713
|
+
children: [
|
|
1714
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "card", d: paths.card }),
|
|
1715
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "faded", d: paths.faded }),
|
|
1716
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "dashed", d: paths.dashed }),
|
|
1717
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "selected", d: paths.selected }),
|
|
1718
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "danger", d: paths.danger }),
|
|
1719
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "warning", d: paths.warning }),
|
|
1720
|
+
/* @__PURE__ */ jsx("path", { "data-shape": "info", d: paths.info })
|
|
1721
|
+
]
|
|
1722
|
+
}
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
function roundRect(rect, r) {
|
|
1726
|
+
const { x, y, width: w, height: h } = rect;
|
|
1727
|
+
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`;
|
|
1728
|
+
}
|
|
1729
|
+
function placedStyle(rect) {
|
|
1730
|
+
return { transform: `translate(${rect.x}px, ${rect.y}px)`, width: `${rect.width}px`, height: `${rect.height}px` };
|
|
1731
|
+
}
|
|
1732
|
+
function intersects(a, b) {
|
|
1733
|
+
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;
|
|
1734
|
+
}
|
|
1735
|
+
function graphWindow(was, view, viewport) {
|
|
1736
|
+
const detail = view.k >= GRAPH_CANVAS_DETAIL_ZOOM;
|
|
1737
|
+
const visible = {
|
|
1738
|
+
x: -view.x / view.k,
|
|
1739
|
+
y: -view.y / view.k,
|
|
1740
|
+
width: viewport.width / view.k,
|
|
1741
|
+
height: viewport.height / view.k
|
|
1742
|
+
};
|
|
1743
|
+
const roomy = {
|
|
1744
|
+
x: visible.x - visible.width / 2,
|
|
1745
|
+
y: visible.y - visible.height / 2,
|
|
1746
|
+
width: visible.width * 2,
|
|
1747
|
+
height: visible.height * 2
|
|
1748
|
+
};
|
|
1749
|
+
if (was && was.detail === detail) {
|
|
1750
|
+
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;
|
|
1751
|
+
const tooLarge = was.rect.width * was.rect.height > 4 * roomy.width * roomy.height;
|
|
1752
|
+
if (inside && !tooLarge) return was;
|
|
1753
|
+
}
|
|
1754
|
+
return { rect: roomy, detail };
|
|
1755
|
+
}
|
|
1756
|
+
function typeAhead(layout, from, text, nameOf) {
|
|
1757
|
+
const order = layout.lanes.flatMap((lane) => lane.items);
|
|
1758
|
+
const lower = text.toLocaleLowerCase();
|
|
1759
|
+
const cycling = [...lower].every((character) => character === lower[0]);
|
|
1760
|
+
const needle = cycling ? lower[0] : lower;
|
|
1761
|
+
const at = order.indexOf(from);
|
|
1762
|
+
const begin = at < 0 ? 0 : at + (cycling ? 1 : 0);
|
|
1763
|
+
for (let step = 0; step < order.length; step++) {
|
|
1764
|
+
const key = order[(begin + step) % order.length];
|
|
1765
|
+
if (nameOf(layout.itemByKey.get(key)).toLocaleLowerCase().startsWith(needle)) return key;
|
|
1766
|
+
}
|
|
1767
|
+
return null;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
export { GRAPH_CANVAS_DETAIL_ZOOM, GRAPH_CANVAS_FIT_FLOOR, GRAPH_CANVAS_LABELS, GRAPH_CANVAS_OPEN_ZOOM, GRAPH_ORDER_SWEEPS, GraphCanvas, graphItemKey, graphNeighbourhood, graphReach, graphStep, graphWindow, layoutGraph, routeGraphEdges };
|