@xeonr/platform-ui 1.10.2 → 1.12.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/dist/auth/AuthCode.d.ts +48 -0
- package/dist/auth/AuthCode.d.ts.map +1 -0
- package/dist/auth/AuthCode.js +197 -0
- package/dist/auth/AuthCode.js.map +1 -0
- package/dist/auth/AuthConsent.d.ts +69 -0
- package/dist/auth/AuthConsent.d.ts.map +1 -0
- package/dist/auth/AuthConsent.js +155 -0
- package/dist/auth/AuthConsent.js.map +1 -0
- package/dist/auth/AuthControls.d.ts +133 -0
- package/dist/auth/AuthControls.d.ts.map +1 -0
- package/dist/auth/AuthControls.js +379 -0
- package/dist/auth/AuthControls.js.map +1 -0
- package/dist/auth/AuthPanel.d.ts +106 -0
- package/dist/auth/AuthPanel.d.ts.map +1 -0
- package/dist/auth/AuthPanel.js +317 -0
- package/dist/auth/AuthPanel.js.map +1 -0
- package/dist/auth.d.ts +5 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +15 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/Anchored.js +109 -109
- package/dist/kit/Anchored.js.map +1 -1
- package/dist/kit/ApiKeyForm.js +73 -73
- package/dist/kit/ApiKeyForm.js.map +1 -1
- package/dist/kit/ApiKeys.js +144 -144
- package/dist/kit/ApiKeys.js.map +1 -1
- package/dist/kit/Badge.js +45 -45
- package/dist/kit/Badge.js.map +1 -1
- package/dist/kit/Blocks.d.ts.map +1 -1
- package/dist/kit/Blocks.js +103 -102
- package/dist/kit/Blocks.js.map +1 -1
- package/dist/kit/Board.js +54 -54
- package/dist/kit/Board.js.map +1 -1
- package/dist/kit/Button.d.ts +3 -3
- package/dist/kit/Button.d.ts.map +1 -1
- package/dist/kit/Button.js +55 -50
- package/dist/kit/Button.js.map +1 -1
- package/dist/kit/Card.d.ts.map +1 -1
- package/dist/kit/Card.js +36 -29
- package/dist/kit/Card.js.map +1 -1
- package/dist/kit/ChartFrame.js +54 -54
- package/dist/kit/ChartFrame.js.map +1 -1
- package/dist/kit/ChartTypes.js +215 -215
- package/dist/kit/ChartTypes.js.map +1 -1
- package/dist/kit/Charts.js +605 -605
- package/dist/kit/Charts.js.map +1 -1
- package/dist/kit/Checkbox.js +16 -16
- package/dist/kit/Checkbox.js.map +1 -1
- package/dist/kit/Chip.js +21 -21
- package/dist/kit/Chip.js.map +1 -1
- package/dist/kit/Choice.js +24 -24
- package/dist/kit/Choice.js.map +1 -1
- package/dist/kit/CodeEditor.d.ts.map +1 -1
- package/dist/kit/CodeEditor.js +26 -48
- package/dist/kit/CodeEditor.js.map +1 -1
- package/dist/kit/Color.js +74 -74
- package/dist/kit/Color.js.map +1 -1
- package/dist/kit/Combobox.js +67 -67
- package/dist/kit/Combobox.js.map +1 -1
- package/dist/kit/CommandPalette.d.ts.map +1 -1
- package/dist/kit/CommandPalette.js +96 -86
- package/dist/kit/CommandPalette.js.map +1 -1
- package/dist/kit/Comment.js +7 -7
- package/dist/kit/Comment.js.map +1 -1
- package/dist/kit/Controls.js +122 -122
- package/dist/kit/Controls.js.map +1 -1
- package/dist/kit/DataGrid.js +97 -97
- package/dist/kit/DataGrid.js.map +1 -1
- package/dist/kit/DataTable.d.ts.map +1 -1
- package/dist/kit/DataTable.js +196 -195
- package/dist/kit/DataTable.js.map +1 -1
- package/dist/kit/DatePicker.js +242 -242
- package/dist/kit/DatePicker.js.map +1 -1
- package/dist/kit/Drawer.d.ts.map +1 -1
- package/dist/kit/Drawer.js +15 -14
- package/dist/kit/Drawer.js.map +1 -1
- package/dist/kit/Dropzone.js +80 -80
- package/dist/kit/Dropzone.js.map +1 -1
- package/dist/kit/Editable.d.ts.map +1 -1
- package/dist/kit/Editable.js +130 -129
- package/dist/kit/Editable.js.map +1 -1
- package/dist/kit/EmptyState.d.ts.map +1 -1
- package/dist/kit/EmptyState.js +14 -13
- package/dist/kit/EmptyState.js.map +1 -1
- package/dist/kit/EntityHeader.d.ts.map +1 -1
- package/dist/kit/EntityHeader.js +17 -16
- package/dist/kit/EntityHeader.js.map +1 -1
- package/dist/kit/Facet.js +52 -52
- package/dist/kit/Facet.js.map +1 -1
- package/dist/kit/FacetRail.js +91 -91
- package/dist/kit/FacetRail.js.map +1 -1
- package/dist/kit/Forbidden.js +7 -7
- package/dist/kit/Forbidden.js.map +1 -1
- package/dist/kit/Form.d.ts.map +1 -1
- package/dist/kit/Form.js +144 -143
- package/dist/kit/Form.js.map +1 -1
- package/dist/kit/Graph.d.ts +14 -3
- package/dist/kit/Graph.d.ts.map +1 -1
- package/dist/kit/Graph.js +473 -314
- package/dist/kit/Graph.js.map +1 -1
- package/dist/kit/GroupedMultiSelect.js +115 -115
- package/dist/kit/GroupedMultiSelect.js.map +1 -1
- package/dist/kit/Icon.d.ts +2 -0
- package/dist/kit/Icon.d.ts.map +1 -1
- package/dist/kit/Icon.js +3 -1
- package/dist/kit/Icon.js.map +1 -1
- package/dist/kit/JumpList.js +11 -11
- package/dist/kit/JumpList.js.map +1 -1
- package/dist/kit/KV.js +6 -6
- package/dist/kit/KV.js.map +1 -1
- package/dist/kit/Layout.js +5 -5
- package/dist/kit/Layout.js.map +1 -1
- package/dist/kit/List.js +74 -74
- package/dist/kit/List.js.map +1 -1
- package/dist/kit/LogView.js +68 -68
- package/dist/kit/LogView.js.map +1 -1
- package/dist/kit/Markdown.js +37 -37
- package/dist/kit/Markdown.js.map +1 -1
- package/dist/kit/Marker.js +42 -42
- package/dist/kit/Marker.js.map +1 -1
- package/dist/kit/Menu.js +128 -128
- package/dist/kit/Menu.js.map +1 -1
- package/dist/kit/Modal.d.ts.map +1 -1
- package/dist/kit/Modal.js +86 -75
- package/dist/kit/Modal.js.map +1 -1
- package/dist/kit/MultiCombobox.js +157 -157
- package/dist/kit/MultiCombobox.js.map +1 -1
- package/dist/kit/PageHeader.d.ts.map +1 -1
- package/dist/kit/PageHeader.js +8 -7
- package/dist/kit/PageHeader.js.map +1 -1
- package/dist/kit/Panel.d.ts.map +1 -1
- package/dist/kit/Panel.js +33 -14
- package/dist/kit/Panel.js.map +1 -1
- package/dist/kit/Picker.js +159 -159
- package/dist/kit/Picker.js.map +1 -1
- package/dist/kit/PipelineFlow.js +86 -86
- package/dist/kit/PipelineFlow.js.map +1 -1
- package/dist/kit/Popover.js +67 -67
- package/dist/kit/Popover.js.map +1 -1
- package/dist/kit/Range.js +76 -76
- package/dist/kit/Range.js.map +1 -1
- package/dist/kit/Reorder.js +95 -95
- package/dist/kit/Reorder.js.map +1 -1
- package/dist/kit/Search.js +27 -27
- package/dist/kit/Search.js.map +1 -1
- package/dist/kit/Secret.js +26 -26
- package/dist/kit/Secret.js.map +1 -1
- package/dist/kit/Skeleton.js +14 -14
- package/dist/kit/Skeleton.js.map +1 -1
- package/dist/kit/Sparkline.js +51 -51
- package/dist/kit/Sparkline.js.map +1 -1
- package/dist/kit/Spectrum.js +163 -163
- package/dist/kit/Spectrum.js.map +1 -1
- package/dist/kit/Splash.js +3 -3
- package/dist/kit/Splash.js.map +1 -1
- package/dist/kit/Split.js +13 -13
- package/dist/kit/Split.js.map +1 -1
- package/dist/kit/SplitButton.d.ts.map +1 -1
- package/dist/kit/SplitButton.js +8 -6
- package/dist/kit/SplitButton.js.map +1 -1
- package/dist/kit/Stat.d.ts.map +1 -1
- package/dist/kit/Stat.js +61 -60
- package/dist/kit/Stat.js.map +1 -1
- package/dist/kit/Stepper.js +22 -22
- package/dist/kit/Stepper.js.map +1 -1
- package/dist/kit/TabStrip.js +68 -68
- package/dist/kit/TabStrip.js.map +1 -1
- package/dist/kit/Text.js +63 -63
- package/dist/kit/Text.js.map +1 -1
- package/dist/kit/Toast.js +29 -29
- package/dist/kit/Toast.js.map +1 -1
- package/dist/kit/Tooltip.js +83 -83
- package/dist/kit/Tooltip.js.map +1 -1
- package/dist/kit/Trace.js +33 -33
- package/dist/kit/Trace.js.map +1 -1
- package/dist/kit/Upload.js +88 -88
- package/dist/kit/Upload.js.map +1 -1
- package/dist/kit/graphLayout.d.ts +32 -0
- package/dist/kit/graphLayout.d.ts.map +1 -0
- package/dist/kit/graphLayout.js +179 -0
- package/dist/kit/graphLayout.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +17 -1
- package/dist/theme/ThemeProvider.d.ts.map +1 -1
- package/dist/theme/ThemeProvider.js +40 -4
- package/dist/theme/ThemeProvider.js.map +1 -1
- package/dist/theme/ThemeScope.d.ts +9 -1
- package/dist/theme/ThemeScope.d.ts.map +1 -1
- package/dist/theme/ThemeScope.js +11 -4
- package/dist/theme/ThemeScope.js.map +1 -1
- package/dist/theme/tokens.d.ts +74 -0
- package/dist/theme/tokens.d.ts.map +1 -1
- package/dist/theme/tokens.js +197 -3
- package/dist/theme/tokens.js.map +1 -1
- package/package.json +12 -6
- package/scripts/check-colour-literals.mjs +5 -1
- package/scripts/stable-styled-ids.mjs +75 -0
package/dist/kit/Graph.js
CHANGED
|
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } fr
|
|
|
3
3
|
import styled, { css, keyframes } from "styled-components";
|
|
4
4
|
import { v } from "../theme/tokens.js";
|
|
5
5
|
import { Tag } from "./Badge.js";
|
|
6
|
+
import { layeredLayout } from "./graphLayout.js";
|
|
6
7
|
// ---------------------------------------------------------------------------
|
|
7
8
|
// Geometry
|
|
8
9
|
// ---------------------------------------------------------------------------
|
|
@@ -13,20 +14,20 @@ const BAND_H = 24;
|
|
|
13
14
|
const DOT = 9;
|
|
14
15
|
const portKey = (node, port, side) => `${side}|${node}|${port}`;
|
|
15
16
|
const TONE_STROKE = {
|
|
16
|
-
|
|
17
|
+
brand: v.brand, ok: v.success, warn: v.warning, crit: v.danger, info: v.info, run: v.running, mut: v.faint, data: v.data
|
|
17
18
|
};
|
|
18
19
|
const TONE_BG = {
|
|
19
|
-
|
|
20
|
+
brand: v.brand08, ok: v.successBg, warn: v.warningBg, crit: v.dangerBg, info: v.infoBg, run: v.runningBg, mut: v.hover, data: v.dataBg
|
|
20
21
|
};
|
|
21
22
|
/** A cubic from an output dot to an input dot; loops back when the input is behind. */
|
|
22
23
|
function curve(a, b) {
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const dx = Math.max(40, Math.abs(b.x - a.x) / 2);
|
|
25
|
+
return `M${a.x},${a.y} C${a.x + dx},${a.y} ${b.x - dx},${b.y} ${b.x},${b.y}`;
|
|
25
26
|
}
|
|
26
27
|
function midpoint(a, b) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// The midpoint of the cubic above, which for symmetric control points is the
|
|
29
|
+
// average of the ends.
|
|
30
|
+
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
30
31
|
}
|
|
31
32
|
const LANE_H = 12;
|
|
32
33
|
const CORNER = 8;
|
|
@@ -38,44 +39,44 @@ const STUB = 14;
|
|
|
38
39
|
* not overlap.
|
|
39
40
|
*/
|
|
40
41
|
function laned(a, b, laneY) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const x1 = a.x + STUB;
|
|
43
|
+
const x2 = b.x - STUB;
|
|
44
|
+
const r = CORNER;
|
|
45
|
+
return `M${a.x},${a.y} H${x1 - r} Q${x1},${a.y} ${x1},${a.y + r} V${laneY - r} Q${x1},${laneY} ${x1 + r},${laneY}` +
|
|
46
|
+
` H${x2 - r} Q${x2},${laneY} ${x2},${laneY - r} V${b.y + r} Q${x2},${b.y} ${x2 + r},${b.y} H${b.x}`;
|
|
46
47
|
}
|
|
47
48
|
/** Which edges go under the row, and in which lane. */
|
|
48
49
|
function assignLanes(nodes, edges) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
50
|
+
const order = new Map(nodes.map((n, i) => [n.id, i]));
|
|
51
|
+
const spans = [];
|
|
52
|
+
for (const e of edges) {
|
|
53
|
+
const i = order.get(e.from.node);
|
|
54
|
+
const j = order.get(e.to.node);
|
|
55
|
+
if (i === undefined || j === undefined || j === i + 1)
|
|
56
|
+
continue;
|
|
57
|
+
spans.push({ id: e.id, i: Math.min(i, j), j: Math.max(i, j) });
|
|
58
|
+
}
|
|
59
|
+
// The shortest span takes the lane nearest the row, so an edge's stubs cross
|
|
60
|
+
// as few other lanes as the shared source allows.
|
|
61
|
+
spans.sort((p, q) => p.i - q.i || p.j - q.j);
|
|
62
|
+
const lanes = [];
|
|
63
|
+
const out = new Map();
|
|
64
|
+
for (const sp of spans) {
|
|
65
|
+
let lane = lanes.findIndex((last) => last <= sp.i);
|
|
66
|
+
if (lane === -1) {
|
|
67
|
+
lane = lanes.length;
|
|
68
|
+
lanes.push(sp.j);
|
|
69
|
+
} else
|
|
70
|
+
|
|
71
|
+
lanes[lane] = sp.j;
|
|
72
|
+
out.set(sp.id, lane);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
74
75
|
}
|
|
75
76
|
// ---------------------------------------------------------------------------
|
|
76
77
|
// Styles
|
|
77
78
|
// ---------------------------------------------------------------------------
|
|
78
|
-
const Surface = styled.div `
|
|
79
|
+
const Surface = styled.div.withConfig({ componentId: "sc-yq0u64-0" })`
|
|
79
80
|
position: relative;
|
|
80
81
|
overflow: auto;
|
|
81
82
|
border: 1px solid ${v.line};
|
|
@@ -84,15 +85,15 @@ const Surface = styled.div `
|
|
|
84
85
|
background-image: radial-gradient(${v.line} 1px, transparent 1px);
|
|
85
86
|
background-size: 16px 16px;
|
|
86
87
|
`;
|
|
87
|
-
const Content = styled.div `
|
|
88
|
+
const Content = styled.div.withConfig({ componentId: "sc-yq0u64-1" })`
|
|
88
89
|
position: relative;
|
|
89
90
|
display: inline-flex;
|
|
90
91
|
align-items: flex-start;
|
|
91
92
|
gap: ${GAP}px;
|
|
92
|
-
padding: ${(p) =>
|
|
93
|
+
padding: ${(p) => p.$band ? PAD + BAND_H : PAD}px ${PAD}px ${(p) => PAD + (p.$lanes ? 6 + p.$lanes * LANE_H : 0)}px;
|
|
93
94
|
min-width: 100%;
|
|
94
95
|
`;
|
|
95
|
-
const Band = styled.div `
|
|
96
|
+
const Band = styled.div.withConfig({ componentId: "sc-yq0u64-2" })`
|
|
96
97
|
position: absolute;
|
|
97
98
|
height: ${BAND_H - 6}px;
|
|
98
99
|
padding: 0 8px;
|
|
@@ -100,7 +101,7 @@ const Band = styled.div `
|
|
|
100
101
|
align-items: center;
|
|
101
102
|
gap: 6px;
|
|
102
103
|
border: 1px dashed ${v.brand55};
|
|
103
|
-
border-radius: 5px;
|
|
104
|
+
border-radius: min(5px, ${v.rCtl});
|
|
104
105
|
background: ${v.brand08};
|
|
105
106
|
color: ${v.brand};
|
|
106
107
|
font-size: 10.5px;
|
|
@@ -110,39 +111,41 @@ const Band = styled.div `
|
|
|
110
111
|
pointer-events: none;
|
|
111
112
|
code { font-family: ${v.mono}; font-weight: 500; }
|
|
112
113
|
`;
|
|
113
|
-
const NodeBox = styled.div `
|
|
114
|
+
const NodeBox = styled.div.withConfig({ componentId: "sc-yq0u64-3" })`
|
|
114
115
|
position: relative;
|
|
115
116
|
flex: none;
|
|
116
117
|
width: ${(p) => p.$w}px;
|
|
117
|
-
border-radius: 10px;
|
|
118
|
-
background: ${(p) =>
|
|
119
|
-
border: ${(p) =>
|
|
120
|
-
box-shadow: ${(p) =>
|
|
118
|
+
border-radius: min(10px, ${v.rCard});
|
|
119
|
+
background: ${(p) => p.$dim ? v.surface2 : v.surface};
|
|
120
|
+
border: ${(p) => p.$dim ? "1px dashed" : "1.5px solid"} ${(p) => p.$selected ? v.brand : p.$dim ? v.line2 : TONE_STROKE[p.$tone] === v.faint ? v.line2 : TONE_STROKE[p.$tone]};
|
|
121
|
+
box-shadow: ${(p) => p.$selected ? `0 0 0 3px ${v.brand22}` : "none"};
|
|
121
122
|
color: ${v.text};
|
|
122
|
-
cursor: ${(p) =>
|
|
123
|
+
cursor: ${(p) => p.$selectable ? "pointer" : "default"};
|
|
123
124
|
outline: none;
|
|
124
|
-
${(p) => p.$selectable && css
|
|
125
|
+
${(p) => p.$selectable && css`&:hover { border-color: ${v.brand}; }`}
|
|
125
126
|
&:focus-visible { box-shadow: ${v.ring}; }
|
|
126
127
|
`;
|
|
127
|
-
const Head = styled.div `
|
|
128
|
+
const Head = styled.div.withConfig({ componentId: "sc-yq0u64-4" })`
|
|
128
129
|
display: flex;
|
|
129
130
|
align-items: center;
|
|
130
131
|
justify-content: space-between;
|
|
131
132
|
gap: 6px;
|
|
132
133
|
padding: 6px 10px;
|
|
133
134
|
border-bottom: 1px solid ${v.line};
|
|
134
|
-
border-radius: 9px 9px 0 0;
|
|
135
|
-
background: ${(p) =>
|
|
135
|
+
border-radius: min(9px, ${v.rCard}) min(9px, ${v.rCard}) 0 0;
|
|
136
|
+
background: ${(p) => p.$dim || p.$tone === "mut" ? "transparent" : TONE_BG[p.$tone]};
|
|
136
137
|
min-width: 0;
|
|
137
|
-
& > .title { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; font-size: 12.5px; }
|
|
138
|
+
& > .title { flex: 1 1 auto; display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; font-size: 12.5px; }
|
|
138
139
|
/* The kind gives way before the title does: a step called "resize" keeps
|
|
139
140
|
its name, and its kind reads as "image-co…" rather than the reverse. */
|
|
140
|
-
& > .title > .kind { flex:
|
|
141
|
+
& > .title > .kind { flex: 0 1 auto; min-width: 28px; }
|
|
141
142
|
& > .title > .kind > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
142
143
|
& > .title > strong { flex: 0 0 auto; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
|
|
144
|
+
/* With no kind the title has the header to itself (FRG-294). */
|
|
145
|
+
& > .title > strong:only-child { flex: 0 1 auto; max-width: 100%; }
|
|
143
146
|
& > .badge { flex: none; display: inline-flex; }
|
|
144
147
|
`;
|
|
145
|
-
const Body = styled.div `
|
|
148
|
+
const Body = styled.div.withConfig({ componentId: "sc-yq0u64-5" })`
|
|
146
149
|
display: flex;
|
|
147
150
|
align-items: flex-start;
|
|
148
151
|
gap: 4px;
|
|
@@ -150,12 +153,12 @@ const Body = styled.div `
|
|
|
150
153
|
min-height: 34px;
|
|
151
154
|
& > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
152
155
|
`;
|
|
153
|
-
const PortRow = styled.div `
|
|
156
|
+
const PortRow = styled.div.withConfig({ componentId: "sc-yq0u64-6" })`
|
|
154
157
|
position: relative;
|
|
155
158
|
min-height: 20px;
|
|
156
159
|
min-width: 0;
|
|
157
|
-
padding: ${(p) =>
|
|
158
|
-
text-align: ${(p) =>
|
|
160
|
+
padding: ${(p) => p.$side === "in" ? "1px 4px 1px 14px" : "1px 14px 1px 4px"};
|
|
161
|
+
text-align: ${(p) => p.$side === "in" ? "left" : "right"};
|
|
159
162
|
font-size: 11.5px;
|
|
160
163
|
line-height: 18px;
|
|
161
164
|
& > .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
@@ -163,26 +166,26 @@ const PortRow = styled.div `
|
|
|
163
166
|
& > .label.required { font-weight: 600; }
|
|
164
167
|
& > .value { color: ${v.faint}; font-family: ${v.mono}; font-size: 10.5px; line-height: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
165
168
|
`;
|
|
166
|
-
const Dot = styled.span `
|
|
169
|
+
const Dot = styled.span.withConfig({ componentId: "sc-yq0u64-7" })`
|
|
167
170
|
position: absolute;
|
|
168
171
|
top: 5px;
|
|
169
|
-
${(p) =>
|
|
172
|
+
${(p) => p.$side === "in" ? "left" : "right"}: -${DOT / 2 + 1}px;
|
|
170
173
|
width: ${DOT}px;
|
|
171
174
|
height: ${DOT}px;
|
|
172
175
|
border-radius: 50%;
|
|
173
|
-
background: ${(p) =>
|
|
176
|
+
background: ${(p) => p.$target ? v.success : v.brand};
|
|
174
177
|
border: 1.5px solid ${v.surface};
|
|
175
178
|
box-sizing: border-box;
|
|
176
|
-
${(p) => p.$live && css
|
|
177
|
-
${(p) => p.$target && css
|
|
179
|
+
${(p) => p.$live && css`cursor: crosshair; &:hover { transform: scale(1.35); }`}
|
|
180
|
+
${(p) => p.$target && css`transform: scale(1.5); box-shadow: 0 0 0 3px ${v.successBg};`}
|
|
178
181
|
transition: transform 80ms ease;
|
|
179
182
|
`;
|
|
180
|
-
const NoPorts = styled.div `
|
|
183
|
+
const NoPorts = styled.div.withConfig({ componentId: "sc-yq0u64-8" })`
|
|
181
184
|
color: ${v.faint};
|
|
182
185
|
font-size: 11px;
|
|
183
186
|
padding: 1px 8px;
|
|
184
187
|
`;
|
|
185
|
-
const Foot = styled.div `
|
|
188
|
+
const Foot = styled.div.withConfig({ componentId: "sc-yq0u64-9" })`
|
|
186
189
|
padding: 4px 10px 6px;
|
|
187
190
|
border-top: 1px solid ${v.line};
|
|
188
191
|
font-size: 11px;
|
|
@@ -191,8 +194,8 @@ const Foot = styled.div `
|
|
|
191
194
|
& > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
192
195
|
& > .note { color: ${v.danger}; }
|
|
193
196
|
`;
|
|
194
|
-
const march = keyframes
|
|
195
|
-
const Overlay = styled.svg `
|
|
197
|
+
const march = keyframes`to { stroke-dashoffset: -20; }`;
|
|
198
|
+
const Overlay = styled.svg.withConfig({ componentId: "sc-yq0u64-10" })`
|
|
196
199
|
position: absolute;
|
|
197
200
|
top: 0;
|
|
198
201
|
left: 0;
|
|
@@ -206,11 +209,11 @@ const Overlay = styled.svg `
|
|
|
206
209
|
.flow { fill: none; stroke: ${v.faint}; stroke-width: 1.25px; stroke-dasharray: 5 4; opacity: 0.7; }
|
|
207
210
|
.draft { fill: none; stroke: ${v.brand}; stroke-width: 1.5px; stroke-dasharray: 4 3; }
|
|
208
211
|
`;
|
|
209
|
-
const EdgeLabel = styled.div `
|
|
212
|
+
const EdgeLabel = styled.div.withConfig({ componentId: "sc-yq0u64-11" })`
|
|
210
213
|
position: absolute;
|
|
211
214
|
transform: translate(-50%, -50%);
|
|
212
215
|
padding: 1px 6px;
|
|
213
|
-
border-radius: 4px;
|
|
216
|
+
border-radius: min(4px, ${v.rCtl});
|
|
214
217
|
font-size: 10px;
|
|
215
218
|
font-weight: 600;
|
|
216
219
|
white-space: nowrap;
|
|
@@ -219,7 +222,7 @@ const EdgeLabel = styled.div `
|
|
|
219
222
|
border: 1px solid ${(p) => TONE_STROKE[p.$tone]};
|
|
220
223
|
pointer-events: none;
|
|
221
224
|
`;
|
|
222
|
-
const Remove = styled.button `
|
|
225
|
+
const Remove = styled.button.withConfig({ componentId: "sc-yq0u64-12" })`
|
|
223
226
|
position: absolute;
|
|
224
227
|
transform: translate(-50%, -50%);
|
|
225
228
|
width: 20px;
|
|
@@ -236,7 +239,7 @@ const Remove = styled.button `
|
|
|
236
239
|
box-shadow: 0 1px 2px ${v.scrim};
|
|
237
240
|
&:hover { background: ${v.dangerBg}; }
|
|
238
241
|
`;
|
|
239
|
-
const Empty = styled.div `
|
|
242
|
+
const Empty = styled.div.withConfig({ componentId: "sc-yq0u64-13" })`
|
|
240
243
|
padding: 22px;
|
|
241
244
|
text-align: center;
|
|
242
245
|
color: ${v.faint};
|
|
@@ -246,261 +249,417 @@ const Empty = styled.div `
|
|
|
246
249
|
// Component
|
|
247
250
|
// ---------------------------------------------------------------------------
|
|
248
251
|
/**
|
|
249
|
-
* Graph: nodes with ports and the edges between them, in the caller's order
|
|
252
|
+
* Graph: nodes with ports and the edges between them, in the caller's order,
|
|
253
|
+
* or (`layout="layered"`) in columns by dependency depth.
|
|
250
254
|
*
|
|
251
255
|
* Reach for it where the wiring is the content — which step feeds which, and
|
|
252
256
|
* with what. A list of steps whose connections are not the point is a
|
|
253
257
|
* `Steps` walkthrough or a `RowList`; a tree is a `RowList` with `depth`.
|
|
254
258
|
*/
|
|
255
|
-
export function Graph(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
259
|
+
export function Graph(props) {
|
|
260
|
+
return props.layout === "layered" ? _jsx(LayeredGraph, { ...props }) : _jsx(RowGraph, { ...props });
|
|
261
|
+
}
|
|
262
|
+
function RowGraph({ nodes, edges, mode = "view", selected = null, onSelect, onConnect, onDisconnect, flow = true, minHeight = 200, empty, label, className }) {
|
|
263
|
+
const content = useRef(null);
|
|
264
|
+
const portEls = useRef(new Map());
|
|
265
|
+
const nodeEls = useRef(new Map());
|
|
266
|
+
const [m, setM] = useState(null);
|
|
267
|
+
const [picked, setPicked] = useState(null);
|
|
268
|
+
const [draft, setDraft] = useState(null);
|
|
269
|
+
// A drag that started on a port ends with a click on the node it sits in;
|
|
270
|
+
// that click is the drag's, not a selection.
|
|
271
|
+
const dragged = useRef(false);
|
|
272
|
+
const editing = mode === "edit";
|
|
273
|
+
const hasBand = nodes.some((n) => n.group);
|
|
274
|
+
const lanes = useMemo(() => assignLanes(nodes, edges), [nodes, edges]);
|
|
275
|
+
const laneCount = lanes.size ? Math.max(...lanes.values()) + 1 : 0;
|
|
276
|
+
// Measure every port dot and node box relative to the content's origin, and
|
|
277
|
+
// keep the measurement when nothing moved — a state change here re-renders,
|
|
278
|
+
// and a re-render that measures the same numbers must not loop.
|
|
279
|
+
const measure = useCallback(() => {
|
|
280
|
+
const root = content.current;
|
|
281
|
+
if (!root)
|
|
282
|
+
return;
|
|
283
|
+
const origin = root.getBoundingClientRect();
|
|
284
|
+
const ports = {};
|
|
285
|
+
for (const [key, el] of portEls.current) {
|
|
286
|
+
const r = el.getBoundingClientRect();
|
|
287
|
+
ports[key] = { x: r.left - origin.left + r.width / 2, y: r.top - origin.top + r.height / 2 };
|
|
288
|
+
}
|
|
289
|
+
const boxes = {};
|
|
290
|
+
for (const [id, el] of nodeEls.current) {
|
|
291
|
+
const r = el.getBoundingClientRect();
|
|
292
|
+
boxes[id] = { x: r.left - origin.left, y: r.top - origin.top, w: r.width, h: r.height };
|
|
293
|
+
}
|
|
294
|
+
const next = { ports, boxes, w: root.scrollWidth, h: root.scrollHeight };
|
|
295
|
+
setM((prev) => prev && sameMeasure(prev, next) ? prev : next);
|
|
296
|
+
}, []);
|
|
297
|
+
useLayoutEffect(() => {measure();});
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
const root = content.current;
|
|
300
|
+
if (!root || typeof ResizeObserver === "undefined")
|
|
301
|
+
return;
|
|
302
|
+
const ro = new ResizeObserver(() => measure());
|
|
303
|
+
ro.observe(root);
|
|
304
|
+
for (const el of nodeEls.current.values())
|
|
305
|
+
ro.observe(el);
|
|
306
|
+
return () => ro.disconnect();
|
|
307
|
+
}, [measure, nodes.length]);
|
|
308
|
+
// A picked edge that the caller removed, or that stopped existing, is forgotten.
|
|
309
|
+
// Adjusted during render rather than in effects that reset it afterwards.
|
|
310
|
+
if (picked && (!editing || !edges.some((e) => e.id === picked)))
|
|
311
|
+
setPicked(null);
|
|
312
|
+
const register = useCallback((key) => (el) => {
|
|
313
|
+
if (el)
|
|
314
|
+
portEls.current.set(key, el);else
|
|
315
|
+
|
|
316
|
+
portEls.current.delete(key);
|
|
317
|
+
}, []);
|
|
318
|
+
const registerNode = useCallback((id) => (el) => {
|
|
319
|
+
if (el)
|
|
320
|
+
nodeEls.current.set(id, el);else
|
|
321
|
+
|
|
322
|
+
nodeEls.current.delete(id);
|
|
323
|
+
}, []);
|
|
324
|
+
// --- wiring by drag ---------------------------------------------------
|
|
325
|
+
const toLocal = useCallback((e) => {
|
|
326
|
+
const origin = content.current?.getBoundingClientRect();
|
|
327
|
+
return origin ? { x: e.clientX - origin.left, y: e.clientY - origin.top } : { x: 0, y: 0 };
|
|
328
|
+
}, []);
|
|
329
|
+
const startDrag = (node, port, side) => (e) => {
|
|
330
|
+
if (!editing || !onConnect)
|
|
331
|
+
return;
|
|
332
|
+
e.preventDefault();
|
|
333
|
+
e.stopPropagation();
|
|
334
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
335
|
+
setDraft({ from: { node, port, side }, at: toLocal(e), over: null });
|
|
336
|
+
dragged.current = true;
|
|
337
|
+
};
|
|
338
|
+
const moveDrag = (e) => {
|
|
339
|
+
if (!draft)
|
|
340
|
+
return;
|
|
341
|
+
const over = portUnder(e.clientX, e.clientY, draft.from.side === "out" ? "in" : "out");
|
|
342
|
+
setDraft({ ...draft, at: toLocal(e), over: over && over.node !== draft.from.node ? over : null });
|
|
343
|
+
};
|
|
344
|
+
const endDrag = (e) => {
|
|
345
|
+
if (!draft)
|
|
346
|
+
return;
|
|
347
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
348
|
+
const over = portUnder(e.clientX, e.clientY, draft.from.side === "out" ? "in" : "out");
|
|
349
|
+
if (over && over.node !== draft.from.node && onConnect) {
|
|
350
|
+
const a = { node: draft.from.node, port: draft.from.port };
|
|
351
|
+
if (draft.from.side === "out")
|
|
352
|
+
onConnect(a, over);else
|
|
353
|
+
|
|
354
|
+
onConnect(over, a);
|
|
355
|
+
}
|
|
356
|
+
setDraft(null);
|
|
357
|
+
};
|
|
358
|
+
const remove = (edge) => {onDisconnect?.(edge);setPicked(null);};
|
|
359
|
+
const onKey = (e) => {
|
|
360
|
+
if (!editing || !picked)
|
|
361
|
+
return;
|
|
362
|
+
if (e.key === "Delete" || e.key === "Backspace") {
|
|
363
|
+
const edge = edges.find((x) => x.id === picked);
|
|
364
|
+
if (edge) {
|
|
325
365
|
e.preventDefault();
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
else
|
|
347
|
-
onConnect(over, a);
|
|
348
|
-
}
|
|
349
|
-
setDraft(null);
|
|
350
|
-
};
|
|
351
|
-
const remove = (edge) => { onDisconnect?.(edge); setPicked(null); };
|
|
352
|
-
const onKey = (e) => {
|
|
353
|
-
if (!editing || !picked)
|
|
354
|
-
return;
|
|
355
|
-
if (e.key === "Delete" || e.key === "Backspace") {
|
|
356
|
-
const edge = edges.find((x) => x.id === picked);
|
|
357
|
-
if (edge) {
|
|
358
|
-
e.preventDefault();
|
|
359
|
-
remove(edge);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (e.key === "Escape")
|
|
363
|
-
setPicked(null);
|
|
366
|
+
remove(edge);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (e.key === "Escape")
|
|
370
|
+
setPicked(null);
|
|
371
|
+
};
|
|
372
|
+
// --- group bands --------------------------------------------------------
|
|
373
|
+
const bands = useMemo(() => {
|
|
374
|
+
if (!m || !hasBand)
|
|
375
|
+
return [];
|
|
376
|
+
const out = [];
|
|
377
|
+
let cur = null;
|
|
378
|
+
const flush = () => {
|
|
379
|
+
if (!cur)
|
|
380
|
+
return;
|
|
381
|
+
const a = m.boxes[cur.first];
|
|
382
|
+
const b = m.boxes[cur.last];
|
|
383
|
+
if (a && b && cur.count > 1)
|
|
384
|
+
out.push({ key: `${cur.label}:${cur.first}`, label: cur.label, count: cur.count, x: a.x - 6, w: b.x + b.w - a.x + 12 });
|
|
385
|
+
cur = null;
|
|
364
386
|
};
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
387
|
+
for (const n of nodes) {
|
|
388
|
+
if (n.group && cur && cur.label === n.group) {
|
|
389
|
+
cur.last = n.id;
|
|
390
|
+
cur.count++;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
flush();
|
|
394
|
+
if (n.group)
|
|
395
|
+
cur = { label: n.group, first: n.id, last: n.id, count: 1 };
|
|
396
|
+
}
|
|
397
|
+
flush();
|
|
398
|
+
return out;
|
|
399
|
+
}, [m, nodes, hasBand]);
|
|
400
|
+
if (nodes.length === 0) {
|
|
401
|
+
return _jsx(Surface, { className: className, style: { minHeight }, children: _jsx(Empty, { children: empty ?? "Nothing to draw yet." }) });
|
|
402
|
+
}
|
|
403
|
+
const tonesUsed = new Set(["mut"]);
|
|
404
|
+
for (const e of edges)
|
|
405
|
+
tonesUsed.add(e.tone ?? "brand");
|
|
406
|
+
return _jsx(Surface, { className: className, style: { minHeight }, ...(label ? { role: "group", "aria-label": label } : {}), tabIndex: editing ? 0 : undefined, onKeyDown: onKey, onClick: () => setPicked(null), children: _jsxs(Content, { ref: content, "$band": hasBand, "$lanes": laneCount, children: [bands.map((b) => _jsxs(Band, { style: { left: b.x, top: PAD - 2, width: b.w }, children: ["inlined ", _jsx("code", { children: b.label }), " \u00B7 ", b.count, " step", b.count === 1 ? "" : "s"] }, b.key)), nodes.map((n) => {
|
|
407
|
+
const selectable = !n.dim && !!onSelect;
|
|
408
|
+
const tone = n.tone ?? "mut";
|
|
409
|
+
const open = () => {if (selectable)
|
|
410
|
+
onSelect?.(n.id === selected ? null : n.id);};
|
|
411
|
+
const ins = n.inputs ?? [];
|
|
412
|
+
const outs = n.outputs ?? [];
|
|
413
|
+
return _jsxs(NodeBox, { ref: registerNode(n.id), "$w": n.width ?? NODE_W, "$tone": tone, "$dim": !!n.dim, "$selected": selected === n.id, "$selectable": selectable, "data-node": n.id, ...(selectable ? { role: "button", tabIndex: 0, "aria-pressed": selected === n.id } : {}), onClick: (e) => {e.stopPropagation();if (dragged.current) {
|
|
414
|
+
dragged.current = false;
|
|
415
|
+
return;
|
|
416
|
+
}setPicked(null);open();}, onKeyDown: (e) => {if (selectable && (e.key === "Enter" || e.key === " ")) {
|
|
417
|
+
e.preventDefault();
|
|
418
|
+
open();
|
|
419
|
+
}}, children: [_jsxs(Head, { "$tone": tone, "$dim": !!n.dim, children: [_jsxs("span", { className: "title", children: [n.kind ? _jsx(Tag, { className: "kind", "$tone": n.dim ? "mut" : "brand", children: _jsx("span", { children: n.kind }) }) : null, _jsx("strong", { children: n.title })] }), n.badge ? _jsx("span", { className: "badge", children: n.badge }) : null] }), ins.length === 0 && outs.length === 0 && !n.sub && !n.note ? null : _jsxs(Body, { children: [_jsx("div", { children: ins.length === 0 ? n.dim ? null : _jsx(NoPorts, { children: "no inputs" }) : ins.map((p) => _jsxs(PortRow, { "$side": "in", "data-port-row": true, title: p.hint ?? `${p.label}${p.sub ? ` · ${p.sub}` : ""}`, children: [_jsx(Dot, { ref: register(portKey(n.id, p.id, "in")), "$side": "in", "$live": editing && !!onConnect, "$target": !!draft && draft.over?.node === n.id && draft.over.port === p.id, "data-port": p.id, "data-port-node": n.id, "data-port-side": "in", onPointerDown: startDrag(n.id, p.id, "in"), onPointerMove: moveDrag, onPointerUp: endDrag }), _jsxs("div", { className: `label${p.required ? " required" : ""}`, children: [p.label, p.required ? "*" : "", p.sub ? _jsxs("span", { className: "sub", children: [" \u00B7 ", p.sub] }) : null] }), p.value ? _jsxs("div", { className: "value", children: ["= ", p.value] }) : null] }, p.id)) }), _jsx("div", { children: outs.length === 0 ? n.dim ? null : _jsx(NoPorts, { style: { textAlign: "right" }, children: "no outputs" }) : outs.map((p) => _jsxs(PortRow, { "$side": "out", "data-port-row": true, title: p.hint ?? `${p.label}${p.sub ? ` · ${p.sub}` : ""}`, children: [_jsx(Dot, { ref: register(portKey(n.id, p.id, "out")), "$side": "out", "$live": editing && !!onConnect, "$target": !!draft && draft.over?.node === n.id && draft.over.port === p.id, "data-port": p.id, "data-port-node": n.id, "data-port-side": "out", onPointerDown: startDrag(n.id, p.id, "out"), onPointerMove: moveDrag, onPointerUp: endDrag }), _jsxs("div", { className: `label${p.required ? " required" : ""}`, children: [p.label, p.sub ? _jsxs("span", { className: "sub", children: [" \u00B7 ", p.sub] }) : null] })] }, p.id)) })] }), n.sub || n.note ? _jsxs(Foot, { children: [n.sub ? _jsx("div", { children: n.sub }) : null, n.note ? _jsx("div", { className: "note", children: n.note }) : null] }) : null] }, n.id);
|
|
420
|
+
}), m ? (() => {
|
|
421
|
+
const floor = Math.max(0, ...Object.values(m.boxes).map((b) => b.y + b.h));
|
|
422
|
+
const laneY = (lane) => floor + 10 + lane * LANE_H;
|
|
423
|
+
const geometry = (e) => {
|
|
424
|
+
const a = m.ports[portKey(e.from.node, e.from.port, "out")];
|
|
425
|
+
const b = m.ports[portKey(e.to.node, e.to.port, "in")];
|
|
426
|
+
if (!a || !b)
|
|
427
|
+
return null;
|
|
428
|
+
const lane = lanes.get(e.id);
|
|
429
|
+
if (lane === undefined)
|
|
430
|
+
return { d: curve(a, b), mid: midpoint(a, b) };
|
|
431
|
+
const y = laneY(lane);
|
|
432
|
+
return { d: laned(a, b, y), mid: { x: (a.x + STUB + b.x - STUB) / 2, y } };
|
|
379
433
|
};
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
434
|
+
return _jsxs(_Fragment, { children: [_jsxs(Overlay, { width: m.w, height: m.h, "aria-hidden": true, children: [_jsx("defs", { children: [...tonesUsed].map((t) => _jsx("marker", { id: `x-graph-arrow-${t}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0 L10,5 L0,10 z", fill: TONE_STROKE[t] }) }, t)) }), flow ? nodes.slice(0, -1).map((n, i) => {
|
|
435
|
+
const a = m.boxes[n.id];
|
|
436
|
+
const b = m.boxes[nodes[i + 1].id];
|
|
437
|
+
if (!a || !b)
|
|
438
|
+
return null;
|
|
439
|
+
// Through the headers, which every node has at the same height.
|
|
440
|
+
const from = { x: a.x + a.w, y: a.y + 17 };
|
|
441
|
+
const to = { x: b.x, y: b.y + 17 };
|
|
442
|
+
return _jsx("path", { className: "flow", d: curve(from, to), markerEnd: "url(#x-graph-arrow-mut)" }, `flow:${n.id}`);
|
|
443
|
+
}) : null, edges.map((e) => {
|
|
444
|
+
const g = geometry(e);
|
|
445
|
+
if (!g)
|
|
446
|
+
return null;
|
|
447
|
+
const tone = e.tone ?? "brand";
|
|
448
|
+
const d = g.d;
|
|
449
|
+
return _jsxs("g", { children: [_jsx("path", { className: `edge${e.animated ? " animated" : ""}${picked === e.id ? " picked" : ""}`, d: d, stroke: TONE_STROKE[tone], markerEnd: `url(#x-graph-arrow-${tone})` }), _jsx("path", { className: `hit${editing && onDisconnect ? "" : " static"}`, d: d, onClick: (ev) => {ev.stopPropagation();setPicked(picked === e.id ? null : e.id);} })] }, e.id);
|
|
450
|
+
}), draft ? (() => {
|
|
451
|
+
const a = m.ports[portKey(draft.from.node, draft.from.port, draft.from.side)];
|
|
452
|
+
if (!a)
|
|
453
|
+
return null;
|
|
454
|
+
const b = draft.over ? m.ports[portKey(draft.over.node, draft.over.port, draft.from.side === "out" ? "in" : "out")] ?? draft.at : draft.at;
|
|
455
|
+
return _jsx("path", { className: "draft", d: draft.from.side === "out" ? curve(a, b) : curve(b, a) });
|
|
456
|
+
})() : null] }), edges.map((e) => {
|
|
457
|
+
const g = geometry(e);
|
|
458
|
+
if (!g)
|
|
459
|
+
return null;
|
|
460
|
+
const mid = g.mid;
|
|
461
|
+
if (editing && onDisconnect && picked === e.id) {
|
|
462
|
+
return _jsx(Remove, { type: "button", "aria-label": "Remove this connection", title: "Remove this connection", style: { left: mid.x, top: mid.y }, onClick: (ev) => {ev.stopPropagation();remove(e);}, children: "\u00D7" }, `rm:${e.id}`);
|
|
385
463
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
flush();
|
|
391
|
-
return out;
|
|
392
|
-
}, [m, nodes, hasBand]);
|
|
393
|
-
if (nodes.length === 0) {
|
|
394
|
-
return _jsx(Surface, { className: className, style: { minHeight }, children: _jsx(Empty, { children: empty ?? "Nothing to draw yet." }) });
|
|
395
|
-
}
|
|
396
|
-
const tonesUsed = new Set(["mut"]);
|
|
397
|
-
for (const e of edges)
|
|
398
|
-
tonesUsed.add(e.tone ?? "brand");
|
|
399
|
-
return (_jsx(Surface, { className: className, style: { minHeight }, ...(label ? { role: "group", "aria-label": label } : {}), tabIndex: editing ? 0 : undefined, onKeyDown: onKey, onClick: () => setPicked(null), children: _jsxs(Content, { ref: content, "$band": hasBand, "$lanes": laneCount, children: [bands.map((b) => (_jsxs(Band, { style: { left: b.x, top: PAD - 2, width: b.w }, children: ["inlined ", _jsx("code", { children: b.label }), " \u00B7 ", b.count, " step", b.count === 1 ? "" : "s"] }, b.key))), nodes.map((n) => {
|
|
400
|
-
const selectable = !n.dim && !!onSelect;
|
|
401
|
-
const tone = n.tone ?? "mut";
|
|
402
|
-
const open = () => { if (selectable)
|
|
403
|
-
onSelect?.(n.id === selected ? null : n.id); };
|
|
404
|
-
const ins = n.inputs ?? [];
|
|
405
|
-
const outs = n.outputs ?? [];
|
|
406
|
-
return (_jsxs(NodeBox, { ref: registerNode(n.id), "$w": n.width ?? NODE_W, "$tone": tone, "$dim": !!n.dim, "$selected": selected === n.id, "$selectable": selectable, "data-node": n.id, ...(selectable ? { role: "button", tabIndex: 0, "aria-pressed": selected === n.id } : {}), onClick: (e) => { e.stopPropagation(); if (dragged.current) {
|
|
407
|
-
dragged.current = false;
|
|
408
|
-
return;
|
|
409
|
-
} setPicked(null); open(); }, onKeyDown: (e) => { if (selectable && (e.key === "Enter" || e.key === " ")) {
|
|
410
|
-
e.preventDefault();
|
|
411
|
-
open();
|
|
412
|
-
} }, children: [_jsxs(Head, { "$tone": tone, "$dim": !!n.dim, children: [_jsxs("span", { className: "title", children: [n.kind ? _jsx(Tag, { className: "kind", "$tone": n.dim ? "mut" : "brand", children: _jsx("span", { children: n.kind }) }) : null, _jsx("strong", { children: n.title })] }), n.badge ? _jsx("span", { className: "badge", children: n.badge }) : null] }), ins.length === 0 && outs.length === 0 && !n.sub && !n.note ? null : (_jsxs(Body, { children: [_jsx("div", { children: ins.length === 0 ? (n.dim ? null : _jsx(NoPorts, { children: "no inputs" })) : ins.map((p) => (_jsxs(PortRow, { "$side": "in", "data-port-row": true, title: p.hint ?? `${p.label}${p.sub ? ` · ${p.sub}` : ""}`, children: [_jsx(Dot, { ref: register(portKey(n.id, p.id, "in")), "$side": "in", "$live": editing && !!onConnect, "$target": !!draft && draft.over?.node === n.id && draft.over.port === p.id, "data-port": p.id, "data-port-node": n.id, "data-port-side": "in", onPointerDown: startDrag(n.id, p.id, "in"), onPointerMove: moveDrag, onPointerUp: endDrag }), _jsxs("div", { className: `label${p.required ? " required" : ""}`, children: [p.label, p.required ? "*" : "", p.sub ? _jsxs("span", { className: "sub", children: [" \u00B7 ", p.sub] }) : null] }), p.value ? _jsxs("div", { className: "value", children: ["= ", p.value] }) : null] }, p.id))) }), _jsx("div", { children: outs.length === 0 ? (n.dim ? null : _jsx(NoPorts, { style: { textAlign: "right" }, children: "no outputs" })) : outs.map((p) => (_jsxs(PortRow, { "$side": "out", "data-port-row": true, title: p.hint ?? `${p.label}${p.sub ? ` · ${p.sub}` : ""}`, children: [_jsx(Dot, { ref: register(portKey(n.id, p.id, "out")), "$side": "out", "$live": editing && !!onConnect, "$target": !!draft && draft.over?.node === n.id && draft.over.port === p.id, "data-port": p.id, "data-port-node": n.id, "data-port-side": "out", onPointerDown: startDrag(n.id, p.id, "out"), onPointerMove: moveDrag, onPointerUp: endDrag }), _jsxs("div", { className: `label${p.required ? " required" : ""}`, children: [p.label, p.sub ? _jsxs("span", { className: "sub", children: [" \u00B7 ", p.sub] }) : null] })] }, p.id))) })] })), n.sub || n.note ? (_jsxs(Foot, { children: [n.sub ? _jsx("div", { children: n.sub }) : null, n.note ? _jsx("div", { className: "note", children: n.note }) : null] })) : null] }, n.id));
|
|
413
|
-
}), m ? (() => {
|
|
414
|
-
const floor = Math.max(0, ...Object.values(m.boxes).map((b) => b.y + b.h));
|
|
415
|
-
const laneY = (lane) => floor + 10 + lane * LANE_H;
|
|
416
|
-
const geometry = (e) => {
|
|
417
|
-
const a = m.ports[portKey(e.from.node, e.from.port, "out")];
|
|
418
|
-
const b = m.ports[portKey(e.to.node, e.to.port, "in")];
|
|
419
|
-
if (!a || !b)
|
|
420
|
-
return null;
|
|
421
|
-
const lane = lanes.get(e.id);
|
|
422
|
-
if (lane === undefined)
|
|
423
|
-
return { d: curve(a, b), mid: midpoint(a, b) };
|
|
424
|
-
const y = laneY(lane);
|
|
425
|
-
return { d: laned(a, b, y), mid: { x: (a.x + STUB + b.x - STUB) / 2, y } };
|
|
426
|
-
};
|
|
427
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Overlay, { width: m.w, height: m.h, "aria-hidden": true, children: [_jsx("defs", { children: [...tonesUsed].map((t) => (_jsx("marker", { id: `x-graph-arrow-${t}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0 L10,5 L0,10 z", fill: TONE_STROKE[t] }) }, t))) }), flow ? nodes.slice(0, -1).map((n, i) => {
|
|
428
|
-
const a = m.boxes[n.id];
|
|
429
|
-
const b = m.boxes[nodes[i + 1].id];
|
|
430
|
-
if (!a || !b)
|
|
431
|
-
return null;
|
|
432
|
-
// Through the headers, which every node has at the same height.
|
|
433
|
-
const from = { x: a.x + a.w, y: a.y + 17 };
|
|
434
|
-
const to = { x: b.x, y: b.y + 17 };
|
|
435
|
-
return _jsx("path", { className: "flow", d: curve(from, to), markerEnd: "url(#x-graph-arrow-mut)" }, `flow:${n.id}`);
|
|
436
|
-
}) : null, edges.map((e) => {
|
|
437
|
-
const g = geometry(e);
|
|
438
|
-
if (!g)
|
|
439
|
-
return null;
|
|
440
|
-
const tone = e.tone ?? "brand";
|
|
441
|
-
const d = g.d;
|
|
442
|
-
return (_jsxs("g", { children: [_jsx("path", { className: `edge${e.animated ? " animated" : ""}${picked === e.id ? " picked" : ""}`, d: d, stroke: TONE_STROKE[tone], markerEnd: `url(#x-graph-arrow-${tone})` }), _jsx("path", { className: `hit${editing && onDisconnect ? "" : " static"}`, d: d, onClick: (ev) => { ev.stopPropagation(); setPicked(picked === e.id ? null : e.id); } })] }, e.id));
|
|
443
|
-
}), draft ? (() => {
|
|
444
|
-
const a = m.ports[portKey(draft.from.node, draft.from.port, draft.from.side)];
|
|
445
|
-
if (!a)
|
|
446
|
-
return null;
|
|
447
|
-
const b = draft.over ? m.ports[portKey(draft.over.node, draft.over.port, draft.from.side === "out" ? "in" : "out")] ?? draft.at : draft.at;
|
|
448
|
-
return _jsx("path", { className: "draft", d: draft.from.side === "out" ? curve(a, b) : curve(b, a) });
|
|
449
|
-
})() : null] }), edges.map((e) => {
|
|
450
|
-
const g = geometry(e);
|
|
451
|
-
if (!g)
|
|
452
|
-
return null;
|
|
453
|
-
const mid = g.mid;
|
|
454
|
-
if (editing && onDisconnect && picked === e.id) {
|
|
455
|
-
return _jsx(Remove, { type: "button", "aria-label": "Remove this connection", title: "Remove this connection", style: { left: mid.x, top: mid.y }, onClick: (ev) => { ev.stopPropagation(); remove(e); }, children: "\u00D7" }, `rm:${e.id}`);
|
|
456
|
-
}
|
|
457
|
-
return e.label ? _jsx(EdgeLabel, { "$tone": e.tone ?? "brand", style: { left: mid.x, top: mid.y }, children: e.label }, `lb:${e.id}`) : null;
|
|
458
|
-
})] }));
|
|
459
|
-
})() : null] }) }));
|
|
464
|
+
return e.label ? _jsx(EdgeLabel, { "$tone": e.tone ?? "brand", style: { left: mid.x, top: mid.y }, children: e.label }, `lb:${e.id}`) : null;
|
|
465
|
+
})] });
|
|
466
|
+
})() : null] }) });
|
|
460
467
|
}
|
|
461
468
|
function sameMeasure(a, b) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
469
|
+
if (a.w !== b.w || a.h !== b.h)
|
|
470
|
+
return false;
|
|
471
|
+
const ak = Object.keys(a.ports);
|
|
472
|
+
const bk = Object.keys(b.ports);
|
|
473
|
+
if (ak.length !== bk.length)
|
|
474
|
+
return false;
|
|
475
|
+
for (const k of bk) {
|
|
476
|
+
const p = a.ports[k];
|
|
477
|
+
const q = b.ports[k];
|
|
478
|
+
if (!p || Math.abs(p.x - q.x) > 0.5 || Math.abs(p.y - q.y) > 0.5)
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
const an = Object.keys(a.boxes);
|
|
482
|
+
const bn = Object.keys(b.boxes);
|
|
483
|
+
if (an.length !== bn.length)
|
|
484
|
+
return false;
|
|
485
|
+
for (const k of bn) {
|
|
486
|
+
const p = a.boxes[k];
|
|
487
|
+
const q = b.boxes[k];
|
|
488
|
+
if (!p || Math.abs(p.x - q.x) > 0.5 || Math.abs(p.y - q.y) > 0.5 || Math.abs(p.w - q.w) > 0.5 || Math.abs(p.h - q.h) > 0.5)
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
return true;
|
|
485
492
|
}
|
|
486
493
|
/** The port dot under a point, of the side a drag can land on; the dot is tiny, so its row counts too. */
|
|
487
494
|
function portUnder(x, y, side) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
495
|
+
if (typeof document === "undefined")
|
|
496
|
+
return null;
|
|
497
|
+
let el = document.elementFromPoint(x, y);
|
|
498
|
+
while (el && !(el instanceof HTMLElement && el.dataset.port !== undefined)) {
|
|
499
|
+
if (el instanceof HTMLElement && el.dataset.node !== undefined)
|
|
500
|
+
break;
|
|
501
|
+
el = el.parentElement;
|
|
502
|
+
}
|
|
503
|
+
if (el instanceof HTMLElement && el.dataset.port !== undefined && el.dataset.portSide === side && el.dataset.portNode) {
|
|
504
|
+
return { node: el.dataset.portNode, port: el.dataset.port };
|
|
505
|
+
}
|
|
506
|
+
// Not on a dot: the row the dot sits in also takes the drop.
|
|
507
|
+
const row = document.elementFromPoint(x, y)?.closest("[data-port-row]");
|
|
508
|
+
const dot = row?.querySelector(`[data-port-side="${side}"]`);
|
|
509
|
+
if (dot?.dataset.portNode && dot.dataset.port !== undefined)
|
|
510
|
+
return { node: dot.dataset.portNode, port: dot.dataset.port };
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
// ---------------------------------------------------------------------------
|
|
514
|
+
// Layered layout
|
|
515
|
+
// ---------------------------------------------------------------------------
|
|
516
|
+
const COL_GAP = 44;
|
|
517
|
+
const ROW_GAP = 14;
|
|
518
|
+
const PASS_W = 20;
|
|
519
|
+
const COMPACT_W = 168;
|
|
520
|
+
const GUESS_H = { full: 64, compact: 44 };
|
|
521
|
+
const LayeredContent = styled.div.withConfig({ componentId: "sc-yq0u64-14" })`
|
|
522
|
+
position: relative;
|
|
523
|
+
min-width: 100%;
|
|
524
|
+
`;
|
|
525
|
+
const Placed = styled.div.withConfig({ componentId: "sc-yq0u64-15" })`
|
|
526
|
+
position: absolute;
|
|
527
|
+
transition: opacity 120ms ease;
|
|
528
|
+
opacity: ${(p) => p.$faded ? 0.35 : 1};
|
|
529
|
+
`;
|
|
530
|
+
const Compact = styled.div.withConfig({ componentId: "sc-yq0u64-16" })`
|
|
531
|
+
display: grid;
|
|
532
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
533
|
+
align-items: center;
|
|
534
|
+
column-gap: 8px;
|
|
535
|
+
min-height: ${GUESS_H.compact - 3}px;
|
|
536
|
+
padding: 5px 10px;
|
|
537
|
+
border-radius: min(9px, ${v.rCard});
|
|
538
|
+
background: ${(p) => p.$dim || p.$tone === "mut" ? "transparent" : TONE_BG[p.$tone]};
|
|
539
|
+
font-size: 12.5px;
|
|
540
|
+
line-height: 16px;
|
|
541
|
+
& > .icon { grid-row: span 2; display: inline-flex; }
|
|
542
|
+
& > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
|
|
543
|
+
& > .sub { min-width: 0; color: ${v.muted}; font-size: 11px; line-height: 14px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
544
|
+
& > :only-child, & > .icon + strong:last-child { grid-row: auto; }
|
|
545
|
+
`;
|
|
546
|
+
const LayeredOverlay = styled(Overlay).withConfig({ componentId: "sc-yq0u64-17" })`
|
|
547
|
+
.edge { transition: opacity 120ms ease; }
|
|
548
|
+
.edge.faded { opacity: 0.18; }
|
|
549
|
+
.edge.lit { stroke-width: 2.25px; }
|
|
550
|
+
`;
|
|
551
|
+
/** A path through points: a curve across each gap between columns, a straight run through each column passed. */
|
|
552
|
+
function connector(points) {
|
|
553
|
+
let d = `M${points[0].x},${points[0].y}`;
|
|
554
|
+
for (let i = 1; i < points.length; i++) {
|
|
555
|
+
const a = points[i - 1];
|
|
556
|
+
const b = points[i];
|
|
557
|
+
if (i % 2 === 1) {
|
|
558
|
+
const dx = (b.x - a.x) / 2;
|
|
559
|
+
d += ` C${a.x + dx},${a.y} ${b.x - dx},${b.y} ${b.x},${b.y}`;
|
|
560
|
+
} else
|
|
561
|
+
|
|
562
|
+
d += ` L${b.x},${b.y}`;
|
|
563
|
+
}
|
|
564
|
+
return d;
|
|
565
|
+
}
|
|
566
|
+
function LayeredGraph({ nodes, edges, selected = null, onSelect, minHeight = 200, empty, label, className, reduce = true, density = "full" }) {
|
|
567
|
+
const compact = density === "compact";
|
|
568
|
+
const byId = useMemo(() => new Map(nodes.map((n) => [n.id, n])), [nodes]);
|
|
569
|
+
const edgeById = useMemo(() => new Map(edges.map((e) => [e.id, e])), [edges]);
|
|
570
|
+
const layout = useMemo(() => layeredLayout(nodes.map((n) => n.id), edges.map((e) => ({ id: e.id, from: e.from.node, to: e.to.node })), reduce), [nodes, edges, reduce]);
|
|
571
|
+
const nodeEls = useRef(new Map());
|
|
572
|
+
const [heights, setHeights] = useState({});
|
|
573
|
+
const [lit, setLit] = useState(null);
|
|
574
|
+
const measure = useCallback(() => {
|
|
575
|
+
const next = {};
|
|
576
|
+
for (const [id, el] of nodeEls.current)
|
|
577
|
+
next[id] = el.offsetHeight;
|
|
578
|
+
setHeights((prev) => {
|
|
579
|
+
const pk = Object.keys(prev);
|
|
580
|
+
const nk = Object.keys(next);
|
|
581
|
+
if (pk.length === nk.length && nk.every((k) => Math.abs((prev[k] ?? -1) - next[k]) < 0.5))
|
|
582
|
+
return prev;
|
|
583
|
+
return next;
|
|
584
|
+
});
|
|
585
|
+
}, []);
|
|
586
|
+
// A ResizeObserver reports each element once when observed, then on every
|
|
587
|
+
// change: that is the first measurement too (until then, a guess per density).
|
|
588
|
+
const nodeSet = nodes.map((n) => n.id).join("\u0000");
|
|
589
|
+
useEffect(() => {
|
|
590
|
+
if (typeof ResizeObserver === "undefined")
|
|
591
|
+
return;
|
|
592
|
+
const ro = new ResizeObserver(() => measure());
|
|
593
|
+
for (const el of nodeEls.current.values())
|
|
594
|
+
ro.observe(el);
|
|
595
|
+
return () => ro.disconnect();
|
|
596
|
+
}, [measure, nodeSet]);
|
|
597
|
+
const registerNode = useCallback((id) => (el) => {
|
|
598
|
+
if (el)
|
|
599
|
+
nodeEls.current.set(id, el);else
|
|
600
|
+
|
|
601
|
+
nodeEls.current.delete(id);
|
|
602
|
+
}, []);
|
|
603
|
+
// A node that left the graph stops being lit.
|
|
604
|
+
if (lit && !byId.has(lit))
|
|
605
|
+
setLit(null);
|
|
606
|
+
if (nodes.length === 0) {
|
|
607
|
+
return _jsx(Surface, { className: className, style: { minHeight }, children: _jsx(Empty, { children: empty ?? "Nothing to draw yet." }) });
|
|
608
|
+
}
|
|
609
|
+
// Geometry: every column as wide as its widest node, every slot one pitch tall,
|
|
610
|
+
// each column centred on the tallest.
|
|
611
|
+
const widthOf = (id) => byId.get(id)?.width ?? (compact ? COMPACT_W : NODE_W);
|
|
612
|
+
const tallest = Math.max(GUESS_H[density], ...Object.values(heights));
|
|
613
|
+
const pitch = tallest + ROW_GAP;
|
|
614
|
+
const cols = layout.columns;
|
|
615
|
+
const colW = cols.map((c) => Math.max(PASS_W, ...c.map((s) => s.kind === "node" ? widthOf(s.id) : PASS_W)));
|
|
616
|
+
const colX = [];
|
|
617
|
+
cols.forEach((_, i) => colX.push(i === 0 ? PAD : colX[i - 1] + colW[i - 1] + COL_GAP));
|
|
618
|
+
const most = Math.max(1, ...cols.map((c) => c.length));
|
|
619
|
+
const slotTop = (c, i) => PAD + ((most - cols[c].length) / 2 + i) * pitch;
|
|
620
|
+
const box = {};
|
|
621
|
+
cols.forEach((col, c) => col.forEach((s, i) => {
|
|
622
|
+
if (s.kind !== "node")
|
|
623
|
+
return;
|
|
624
|
+
const h = heights[s.id] ?? GUESS_H[density];
|
|
625
|
+
box[s.id] = { x: colX[c], y: slotTop(c, i) + (tallest - h) / 2, w: widthOf(s.id), h };
|
|
626
|
+
}));
|
|
627
|
+
const W = colX[cols.length - 1] + colW[cols.length - 1] + PAD;
|
|
628
|
+
const H = PAD * 2 + most * pitch - ROW_GAP;
|
|
629
|
+
const mid = (c, i) => slotTop(c, i) + tallest / 2;
|
|
630
|
+
const related = lit ? layout.related(lit) : null;
|
|
631
|
+
const tonesUsed = new Set(["mut"]);
|
|
632
|
+
for (const e of layout.edges)
|
|
633
|
+
tonesUsed.add(edgeById.get(e.id)?.tone ?? "brand");
|
|
634
|
+
return _jsx(Surface, { className: className, style: { minHeight }, ...(label ? { role: "group", "aria-label": label } : {}), children: _jsxs(LayeredContent, { style: { width: W, height: Math.max(H, minHeight - 2) }, children: [_jsxs(LayeredOverlay, { width: W, height: H, "aria-hidden": true, children: [_jsx("defs", { children: [...tonesUsed].map((t) => _jsx("marker", { id: `x-graph-arrow-${t}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0 L10,5 L0,10 z", fill: TONE_STROKE[t] }) }, t)) }), layout.edges.map((le) => {
|
|
635
|
+
const e = edgeById.get(le.id);
|
|
636
|
+
const a = box[le.from];
|
|
637
|
+
const b = box[le.to];
|
|
638
|
+
if (!e || !a || !b)
|
|
639
|
+
return null;
|
|
640
|
+
const points = [{ x: a.x + a.w, y: a.y + a.h / 2 }];
|
|
641
|
+
const from = layout.column.get(le.from);
|
|
642
|
+
(layout.passes.get(le.id) ?? []).forEach((slot, k) => {
|
|
643
|
+
const c = from + 1 + k;
|
|
644
|
+
const y = mid(c, slot);
|
|
645
|
+
points.push({ x: colX[c], y }, { x: colX[c] + colW[c], y });
|
|
646
|
+
});
|
|
647
|
+
points.push({ x: b.x - 2, y: b.y + b.h / 2 });
|
|
648
|
+
const tone = e.tone ?? "brand";
|
|
649
|
+
const on = related ? related.has(le.from) && related.has(le.to) : false;
|
|
650
|
+
const cls = `edge${e.animated ? " animated" : ""}${related ? on ? " lit" : " faded" : ""}`;
|
|
651
|
+
return _jsx("path", { className: cls, d: connector(points), stroke: TONE_STROKE[tone], markerEnd: `url(#x-graph-arrow-${tone})`, "data-edge": le.id }, le.id);
|
|
652
|
+
})] }), cols.flatMap((col) => col).filter((s) => s.kind === "node").map((s) => {
|
|
653
|
+
const n = byId.get(s.id);
|
|
654
|
+
const b = box[n.id];
|
|
655
|
+
const selectable = !n.dim && !!onSelect;
|
|
656
|
+
const tone = n.tone ?? "mut";
|
|
657
|
+
const open = () => {if (selectable)
|
|
658
|
+
onSelect?.(n.id === selected ? null : n.id);};
|
|
659
|
+
return _jsx(Placed, { "$faded": !!related && !related.has(n.id), style: { left: b.x, top: b.y, width: b.w }, children: _jsx(NodeBox, { ref: registerNode(n.id), "$w": b.w, "$tone": tone, "$dim": !!n.dim, "$selected": selected === n.id, "$selectable": selectable, "data-node": n.id, ...(selectable ? { role: "button", tabIndex: 0, "aria-pressed": selected === n.id } : { tabIndex: 0 }), ...(n.ariaLabel ? { "aria-label": n.ariaLabel } : {}), onMouseEnter: () => setLit(n.id), onMouseLeave: () => setLit((x) => x === n.id ? null : x), onFocus: () => setLit(n.id), onBlur: () => setLit((x) => x === n.id ? null : x), onClick: open, onKeyDown: (e) => {if (selectable && (e.key === "Enter" || e.key === " ")) {
|
|
660
|
+
e.preventDefault();
|
|
661
|
+
open();
|
|
662
|
+
}}, children: compact ? _jsxs(Compact, { "$tone": tone, "$dim": !!n.dim, children: [n.icon ? _jsx("span", { className: "icon", children: n.icon }) : null, _jsx("strong", { title: typeof n.title === "string" ? n.title : undefined, children: n.title }), n.sub ? _jsx("span", { className: "sub", children: n.sub }) : null] }) : _jsxs(_Fragment, { children: [_jsxs(Head, { "$tone": tone, "$dim": !!n.dim, style: n.sub || n.note ? undefined : { borderBottom: "none", borderRadius: `min(9px, ${v.rCard})` }, children: [_jsxs("span", { className: "title", children: [n.icon ? _jsx("span", { style: { display: "inline-flex", flex: "none" }, children: n.icon }) : null, n.kind ? _jsx(Tag, { className: "kind", "$tone": n.dim ? "mut" : "brand", children: _jsx("span", { children: n.kind }) }) : null, _jsx("strong", { children: n.title })] }), n.badge ? _jsx("span", { className: "badge", children: n.badge }) : null] }), n.sub || n.note ? _jsxs(Foot, { style: { borderTop: "none" }, children: [n.sub ? _jsx("div", { children: n.sub }) : null, n.note ? _jsx("div", { className: "note", children: n.note }) : null] }) : null] }) }) }, n.id);
|
|
663
|
+
})] }) });
|
|
505
664
|
}
|
|
506
|
-
//# sourceMappingURL=Graph.js.map
|
|
665
|
+
//# sourceMappingURL=Graph.js.map
|