@momoi-labs/kiso-react 0.23.0 → 0.25.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/accent-selector.d.ts +1 -1
- package/dist/accent-selector.js +3 -0
- package/dist/combobox.d.ts +35 -0
- package/dist/combobox.js +131 -0
- package/dist/diagram-routes.d.ts +116 -0
- package/dist/diagram-routes.js +1175 -0
- package/dist/diagram.d.ts +74 -5
- package/dist/diagram.js +241 -85
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/styles.css +6 -0
- package/package.json +2 -2
package/dist/diagram.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type LucideIcon } from "lucide-react";
|
|
3
|
+
import { type DiagramArrow, type DiagramCrossings, type DiagramEdgeLine, type DiagramEdgeRoute, type DiagramEdgeShape, type DiagramEdgeTone, type DiagramLabels } from "./diagram-routes.js";
|
|
4
|
+
export type { DiagramArrow, DiagramCrossings, DiagramEdgeLine, DiagramEdgeRoute, DiagramEdgeShape, DiagramEdgeTone, DiagramLabels };
|
|
3
5
|
export type DiagramKind = "route" | "service" | "repository" | "image" | "database";
|
|
4
6
|
export type DiagramBackground = "solid" | "dots" | "grid" | "crosses" | "construction" | "guides" | "fibers";
|
|
5
7
|
export type DiagramStatus = "stopped" | "failed";
|
|
6
|
-
export type
|
|
7
|
-
export type DiagramEdgeTone = "neutral" | "success" | "danger";
|
|
8
|
+
export type DiagramDirection = "right" | "down" | "grid";
|
|
8
9
|
export type DiagramBorderStyle = "solid" | "none" | "rail" | "dash" | "bevel" | "double" | "base" | "offset" | "manga" | "brush";
|
|
9
10
|
export type DiagramCornerStyle = "square" | "rounded" | "asym" | "pixel";
|
|
10
11
|
export type DiagramCornerSize = "off" | "small" | "medium" | "large";
|
|
@@ -18,13 +19,57 @@ export type DiagramFrameProps = {
|
|
|
18
19
|
export type DiagramProps = Omit<React.ComponentProps<"div">, "children"> & DiagramFrameProps & {
|
|
19
20
|
/** Names the drawing for assistive technology. */
|
|
20
21
|
label: string;
|
|
22
|
+
/** `right` (default) reads DiagramColumns left to right; `down` reads
|
|
23
|
+
DiagramRows top to bottom; `grid` lays bands of DiagramColumns on
|
|
24
|
+
shared columns, and each edge picks its route. */
|
|
25
|
+
direction?: DiagramDirection;
|
|
26
|
+
/** The number of shared columns in a grid. */
|
|
27
|
+
columns?: number;
|
|
28
|
+
/** How an edge draws where it crosses a frame or another edge. */
|
|
29
|
+
crossings?: DiagramCrossings;
|
|
30
|
+
/** `auto` turns a label on a vertical run when it fits. */
|
|
31
|
+
labels?: DiagramLabels;
|
|
32
|
+
/** How edges are drawn: `orthogonal` (default) with rounded elbows,
|
|
33
|
+
`curve`, `straight`, or `sketch`, hand drawn. A DiagramEdge's `shape`
|
|
34
|
+
overrides it. */
|
|
35
|
+
edges?: DiagramEdgeShape;
|
|
36
|
+
/** The head at the end of each edge. Unset is `triangle`, or `sketch` on a
|
|
37
|
+
sketched edge. A DiagramEdge's `arrow` overrides it. */
|
|
38
|
+
arrow?: DiagramArrow;
|
|
39
|
+
/** A footer inside the card, under a rule, such as the key of the series
|
|
40
|
+
edges built from DiagramEdgeKey. */
|
|
41
|
+
footer?: React.ReactNode;
|
|
21
42
|
/** Unset follows the page's canvas; a page with no canvas gets dots. */
|
|
22
43
|
background?: DiagramBackground;
|
|
23
44
|
strength?: "quiet" | "visible";
|
|
24
45
|
children: React.ReactNode;
|
|
25
46
|
};
|
|
26
|
-
declare function Diagram({ label, background, strength, borderStyle, cornerStyle, cornerSize, cornerMarks, className, children, ...props }: DiagramProps): React.JSX.Element;
|
|
47
|
+
declare function Diagram({ label, direction, columns, crossings, labels, edges: shape, arrow, footer, background, strength, borderStyle, cornerStyle, cornerSize, cornerMarks, className, children, ...props }: DiagramProps): React.JSX.Element;
|
|
27
48
|
declare function DiagramColumn({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
49
|
+
export type DiagramRowProps = React.ComponentProps<"div"> & {
|
|
50
|
+
/** Where the row's nodes sit across the drawing. Center by default. */
|
|
51
|
+
justify?: "center" | "start" | "end" | "between";
|
|
52
|
+
};
|
|
53
|
+
declare function DiagramRow({ justify, className, ...props }: DiagramRowProps): React.JSX.Element;
|
|
54
|
+
export type DiagramGroupLine = "dashed" | "solid" | "dotted";
|
|
55
|
+
export type DiagramGroupTone = "neutral" | "primary" | "info" | "success" | "warning" | "danger";
|
|
56
|
+
export type DiagramGroupProps = Omit<React.ComponentProps<"div">, "title"> & {
|
|
57
|
+
/** The caption in front of the title, such as "Cluster". */
|
|
58
|
+
label?: string;
|
|
59
|
+
/** The name on the border, in weight. */
|
|
60
|
+
title: React.ReactNode;
|
|
61
|
+
/** A line under a rule at the bottom of the frame. */
|
|
62
|
+
footer?: React.ReactNode;
|
|
63
|
+
/** The frame's line: `dashed` (default), `solid` or `dotted`. */
|
|
64
|
+
line?: DiagramGroupLine;
|
|
65
|
+
/** The frame's colour: `neutral` (default) or a tone. */
|
|
66
|
+
tone?: DiagramGroupTone;
|
|
67
|
+
/** The title becomes a button that folds the group to its frame. */
|
|
68
|
+
collapsible?: boolean;
|
|
69
|
+
/** Open by default. */
|
|
70
|
+
defaultOpen?: boolean;
|
|
71
|
+
};
|
|
72
|
+
declare function DiagramGroup({ label, title, footer, line, tone, collapsible, defaultOpen, className, style, children, ...props }: DiagramGroupProps): React.JSX.Element;
|
|
28
73
|
export type DiagramNodeGroupProps = React.ComponentProps<"div"> & DiagramFrameProps;
|
|
29
74
|
declare function DiagramNodeGroup({ borderStyle, cornerStyle, cornerSize, cornerMarks, className, ...props }: DiagramNodeGroupProps): React.JSX.Element;
|
|
30
75
|
export type DiagramNodeProps = Omit<React.ComponentProps<"div">, "title" | "children"> & DiagramFrameProps & {
|
|
@@ -97,8 +142,32 @@ export type DiagramEdgeProps = {
|
|
|
97
142
|
to: string;
|
|
98
143
|
/** Mono text on the run into the target, such as a port or a variable. */
|
|
99
144
|
label?: string;
|
|
145
|
+
/** In a grid, forces the route the edge would otherwise pick from where
|
|
146
|
+
its nodes are: `side`, `down` or `drop`. */
|
|
147
|
+
route?: DiagramEdgeRoute;
|
|
148
|
+
/** Overrides the Diagram's `edges` for this edge. */
|
|
149
|
+
shape?: DiagramEdgeShape;
|
|
150
|
+
/** Overrides the Diagram's `arrow` for this edge. */
|
|
151
|
+
arrow?: DiagramArrow;
|
|
152
|
+
} & ({
|
|
100
153
|
line?: DiagramEdgeLine;
|
|
101
154
|
tone?: DiagramEdgeTone;
|
|
155
|
+
series?: never;
|
|
156
|
+
flow?: never;
|
|
157
|
+
}
|
|
158
|
+
/** A kind of link, such as replication or backups: the chart colour of the
|
|
159
|
+
slot and a dash of its own. `flow` moves the dash toward the target. */
|
|
160
|
+
| {
|
|
161
|
+
series: number;
|
|
162
|
+
flow?: boolean;
|
|
163
|
+
line?: never;
|
|
164
|
+
tone?: never;
|
|
165
|
+
});
|
|
166
|
+
declare function DiagramEdge({ from, to, label, route, line, tone, series, flow, shape, arrow }: DiagramEdgeProps): null;
|
|
167
|
+
export type DiagramEdgeKeyProps = Omit<React.ComponentProps<"span">, "children"> & {
|
|
168
|
+
series: number;
|
|
169
|
+
/** What the series means, such as "WAL to storage". */
|
|
170
|
+
children: React.ReactNode;
|
|
102
171
|
};
|
|
103
|
-
declare function
|
|
104
|
-
export { Diagram, DiagramColumn, DiagramNodeGroup, DiagramNode, DiagramFact, DiagramFold, DiagramFilter, DiagramSection, DiagramLine, DiagramEdge };
|
|
172
|
+
declare function DiagramEdgeKey({ series, className, children, ...props }: DiagramEdgeKeyProps): React.JSX.Element;
|
|
173
|
+
export { Diagram, DiagramColumn, DiagramRow, DiagramGroup, DiagramEdgeKey, DiagramNodeGroup, DiagramNode, DiagramFact, DiagramFold, DiagramFilter, DiagramSection, DiagramLine, DiagramEdge };
|
package/dist/diagram.js
CHANGED
|
@@ -4,8 +4,14 @@ import { clsx as cn } from "clsx";
|
|
|
4
4
|
import { ChevronDown, ChevronUp, Container, Database, GitBranch, Route, Server } from "lucide-react";
|
|
5
5
|
import { Badge } from "./badge.js";
|
|
6
6
|
import { Card } from "./card.js";
|
|
7
|
+
import { chartColor } from "./chart-data.js";
|
|
7
8
|
import { StatusBadge } from "./status-badge.js";
|
|
8
9
|
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
10
|
+
import { draw, route, } from "./diagram-routes.js";
|
|
11
|
+
/* The number of dash patterns in ui.css. Series past it reuse a dash with a
|
|
12
|
+
new colour, so the pair stays unique. */
|
|
13
|
+
const DASHES = 5;
|
|
14
|
+
const dashOf = (series) => ((Math.max(1, Math.round(series)) - 1) % DASHES) + 1;
|
|
9
15
|
const DiagramContext = React.createContext(null);
|
|
10
16
|
function useRegistry(part) {
|
|
11
17
|
const registry = React.useContext(DiagramContext);
|
|
@@ -23,42 +29,28 @@ const kinds = {
|
|
|
23
29
|
image: { label: "Container image", tone: "primary", icon: Container },
|
|
24
30
|
database: { label: "Database", tone: "info", icon: Database },
|
|
25
31
|
};
|
|
32
|
+
/* Heads other than the triangle, in the same 10 by 10 box with the tip at
|
|
33
|
+
x 10 and the marker's reference at x 9, so each sits where the triangle
|
|
34
|
+
does. Open heads are strokes; ui.css paints them. */
|
|
35
|
+
const heads = {
|
|
36
|
+
chevron: _jsx("path", { d: "M 2 1.5 L 9.5 5 L 2 8.5" }),
|
|
37
|
+
stealth: _jsx("path", { d: "M 0 0 L 10 5 L 0 10 L 3 5 z" }),
|
|
38
|
+
dot: _jsx("circle", { cx: "6.6", cy: "5", r: "3.4" }),
|
|
39
|
+
sketch: _jsx("path", { d: "M 0.6 1.8 Q 4.6 2.6 9.4 5.4 M 2 9.8 Q 5 6.8 9.6 4.9" }),
|
|
40
|
+
};
|
|
26
41
|
const statuses = {
|
|
27
42
|
stopped: { label: "Stopped", tone: "neutral" },
|
|
28
43
|
failed: { label: "Failed", tone: "danger" },
|
|
29
44
|
};
|
|
30
|
-
|
|
31
|
-
/* An edge is two paths. The trunk is the horizontal run out of the source,
|
|
32
|
-
shared by every edge that leaves it. It carries their line and tone when
|
|
33
|
-
they all agree, so a single dotted edge is dotted end to end; when they
|
|
34
|
-
differ it stays solid and neutral, since two styles on one line would
|
|
35
|
-
paint over each other. The branch is the rest, the turn onto the merge
|
|
36
|
-
column, the vertical run and the straight run into the target, and it
|
|
37
|
-
carries the edge's line and tone. */
|
|
38
|
-
function elbow(sx, sy, tx, ty, mid) {
|
|
39
|
-
const dy = ty - sy;
|
|
40
|
-
if (Math.abs(dy) < 1)
|
|
41
|
-
return { trunk: `M ${sx} ${sy} H ${mid}`, branch: `M ${mid} ${sy} H ${tx}` };
|
|
42
|
-
const r = Math.max(0, Math.min(RADIUS, Math.abs(dy) / 2, mid - sx, tx - mid));
|
|
43
|
-
const d = Math.sign(dy);
|
|
44
|
-
return {
|
|
45
|
-
trunk: `M ${sx} ${sy} H ${mid - r}`,
|
|
46
|
-
branch: [
|
|
47
|
-
`M ${mid - r} ${sy}`,
|
|
48
|
-
`Q ${mid} ${sy} ${mid} ${sy + d * r}`,
|
|
49
|
-
`V ${ty - d * r}`,
|
|
50
|
-
`Q ${mid} ${ty} ${mid + r} ${ty}`,
|
|
51
|
-
`H ${tx}`,
|
|
52
|
-
].join(" "),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function Diagram({ label, background, strength, borderStyle, cornerStyle, cornerSize, cornerMarks, className, children, ...props }) {
|
|
45
|
+
function Diagram({ label, direction = "right", columns, crossings = "none", labels = "auto", edges: shape, arrow, footer, background, strength, borderStyle, cornerStyle, cornerSize, cornerMarks, className, children, ...props }) {
|
|
56
46
|
const frame = React.useRef(null);
|
|
57
47
|
const scroll = React.useRef(null);
|
|
48
|
+
const lanes = React.useRef(null);
|
|
49
|
+
const svg = React.useRef(null);
|
|
58
50
|
const nodes = React.useRef(new Map()).current;
|
|
59
|
-
const [
|
|
51
|
+
const [registered, setRegistered] = React.useState([]);
|
|
60
52
|
const [version, setVersion] = React.useState(0);
|
|
61
|
-
const [drawn, setDrawn] = React.useState({ paths: [], labels: [] });
|
|
53
|
+
const [drawn, setDrawn] = React.useState({ paths: [], labels: [], plates: [], dots: [] });
|
|
62
54
|
const marker = `${React.useId()}arrow`;
|
|
63
55
|
const register = React.useCallback((id, element) => {
|
|
64
56
|
if (element)
|
|
@@ -68,10 +60,12 @@ function Diagram({ label, background, strength, borderStyle, cornerStyle, corner
|
|
|
68
60
|
setVersion((value) => value + 1);
|
|
69
61
|
}, [nodes]);
|
|
70
62
|
const addEdge = React.useCallback((edge) => {
|
|
71
|
-
|
|
72
|
-
return () =>
|
|
63
|
+
setRegistered((list) => [...list, edge]);
|
|
64
|
+
return () => setRegistered((list) => list.filter((item) => item !== edge));
|
|
73
65
|
}, []);
|
|
74
|
-
const
|
|
66
|
+
const refresh = React.useCallback(() => setVersion((value) => value + 1), []);
|
|
67
|
+
const context = React.useMemo(() => ({ nodes, register, addEdge, refresh, direction }), [nodes, register, addEdge, refresh, direction]);
|
|
68
|
+
const labelSizes = React.useRef(new Map());
|
|
75
69
|
useIsomorphicLayoutEffect(() => {
|
|
76
70
|
const root = frame.current;
|
|
77
71
|
const region = scroll.current;
|
|
@@ -81,78 +75,235 @@ function Diagram({ label, background, strength, borderStyle, cornerStyle, corner
|
|
|
81
75
|
// wrapping only cramps it, so it takes its natural width and scrolls.
|
|
82
76
|
const fit = () => {
|
|
83
77
|
root.removeAttribute("data-overflow");
|
|
84
|
-
|
|
78
|
+
// A node wider than its stage, such as a card with an unbroken URL in
|
|
79
|
+
// a group, spills past the lanes without widening them, so its spill
|
|
80
|
+
// counts as well.
|
|
81
|
+
if (root.offsetWidth > region.clientWidth || root.scrollWidth > root.clientWidth + 1)
|
|
85
82
|
root.setAttribute("data-overflow", "");
|
|
86
83
|
};
|
|
87
|
-
const
|
|
84
|
+
const layout = (pass) => {
|
|
88
85
|
fit();
|
|
89
86
|
const origin = root.getBoundingClientRect();
|
|
87
|
+
const place = (rect) => ({
|
|
88
|
+
left: rect.left - origin.left, right: rect.right - origin.left,
|
|
89
|
+
top: rect.top - origin.top, bottom: rect.bottom - origin.top,
|
|
90
|
+
width: rect.width, height: rect.height,
|
|
91
|
+
});
|
|
92
|
+
// A node inside a folded group is hidden, so its edges reach the
|
|
93
|
+
// outermost folded group around it instead.
|
|
94
|
+
const elements = new Map(nodes);
|
|
95
|
+
const proxies = new Map();
|
|
96
|
+
const resolve = (id) => {
|
|
97
|
+
const element = nodes.get(id);
|
|
98
|
+
if (!element)
|
|
99
|
+
return null;
|
|
100
|
+
let folded = null;
|
|
101
|
+
for (let item = element.closest('.diagram-group[data-open="false"]'); item; item = item.parentElement?.closest('.diagram-group[data-open="false"]') ?? null)
|
|
102
|
+
folded = item;
|
|
103
|
+
if (!folded)
|
|
104
|
+
return id;
|
|
105
|
+
let proxy = proxies.get(folded);
|
|
106
|
+
if (!proxy) {
|
|
107
|
+
proxy = `group:${proxies.size}`;
|
|
108
|
+
proxies.set(folded, proxy);
|
|
109
|
+
elements.set(proxy, folded);
|
|
110
|
+
}
|
|
111
|
+
return proxy;
|
|
112
|
+
};
|
|
90
113
|
const box = (id) => {
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
114
|
+
const element = elements.get(id);
|
|
115
|
+
if (!element)
|
|
93
116
|
return null;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
117
|
+
const rect = place(element.getBoundingClientRect());
|
|
118
|
+
// A node in a DiagramNodeGroup is one part of a stacked card. Read
|
|
119
|
+
// top to bottom, its edges leave and enter the card's own top and
|
|
120
|
+
// bottom, so they never cross the parts above or below it.
|
|
121
|
+
const card = direction !== "right" && !proxies.has(element) ? element.closest(".diagram-node-group")?.getBoundingClientRect() : undefined;
|
|
122
|
+
if (card) {
|
|
123
|
+
rect.top = card.top - origin.top;
|
|
124
|
+
rect.bottom = card.bottom - origin.top;
|
|
125
|
+
rect.height = card.height;
|
|
126
|
+
}
|
|
127
|
+
// A folded frame carries its title on its top border, so an edge
|
|
128
|
+
// into its top ends just under the title instead of behind it.
|
|
129
|
+
const name = proxies.has(element) ? element.querySelector(":scope > .diagram-group-title")?.getBoundingClientRect() : undefined;
|
|
130
|
+
if (name) {
|
|
131
|
+
const top = name.bottom - origin.top;
|
|
132
|
+
rect.height -= top - rect.top;
|
|
133
|
+
rect.top = top;
|
|
134
|
+
}
|
|
135
|
+
return { ...rect, id, x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
|
|
101
136
|
};
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
const measured =
|
|
106
|
-
const
|
|
107
|
-
|
|
137
|
+
// An edge inside one folded group is not drawn, and edges that now
|
|
138
|
+
// join the same ends with the same look are drawn once.
|
|
139
|
+
const seen = new Set();
|
|
140
|
+
const measured = registered.flatMap((edge) => {
|
|
141
|
+
const to = resolve(edge.to);
|
|
142
|
+
if (!to)
|
|
143
|
+
return [];
|
|
144
|
+
// Each source and target pair is drawn once per look, so edges whose
|
|
145
|
+
// source lists overlap after folding do not repeat a connection.
|
|
146
|
+
const looks = `${edge.series ?? ""}|${edge.line ?? ""}|${edge.tone ?? ""}|${edge.shape ?? ""}|${edge.head ?? ""}`;
|
|
147
|
+
const resolved = [...new Set(edge.from.map(resolve))].filter((id) => !!id && id !== to);
|
|
148
|
+
const folded = to !== edge.to || resolved.length !== edge.from.length || resolved.some((id, index) => id !== edge.from[index]);
|
|
149
|
+
const from = folded ? resolved.filter((id) => !seen.has(`${id}->${to}|${looks}`)) : resolved;
|
|
150
|
+
for (const id of from)
|
|
151
|
+
seen.add(`${id}->${to}|${looks}`);
|
|
152
|
+
if (!from.length)
|
|
153
|
+
return [];
|
|
154
|
+
const target = box(to);
|
|
155
|
+
const sources = from.flatMap((id) => {
|
|
108
156
|
const found = box(id);
|
|
109
|
-
return found ? [
|
|
157
|
+
return found ? [found] : [];
|
|
110
158
|
});
|
|
111
|
-
return target && sources.length ? [{ edge, target, sources }] : [];
|
|
159
|
+
return target && sources.length ? [{ edge: folded ? { ...edge, to, from } : edge, target, sources }] : [];
|
|
112
160
|
});
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
161
|
+
const all = [...new Set([...nodes.keys()].map(resolve))].flatMap((id) => {
|
|
162
|
+
const found = id ? box(id) : null;
|
|
163
|
+
return found ? [found] : [];
|
|
164
|
+
});
|
|
165
|
+
const groups = Array.from(lanes.current?.querySelectorAll(".diagram-group") ?? []);
|
|
166
|
+
// Open groups the routes keep their runs out of, unless they hold an
|
|
167
|
+
// end. A folded group is a node already; groups inside it have no box.
|
|
168
|
+
const walls = groups.flatMap((element, index) => {
|
|
169
|
+
if (proxies.has(element))
|
|
170
|
+
return [];
|
|
171
|
+
const rect = place(element.getBoundingClientRect());
|
|
172
|
+
return rect.width && rect.height ? [{ ...rect, id: `frame:${index}`, x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }] : [];
|
|
173
|
+
});
|
|
174
|
+
const routes = route(measured, all, direction, walls);
|
|
175
|
+
// An edge that comes into a group from the side needs room between
|
|
176
|
+
// the border and the node, so the line runs straight after crossing
|
|
177
|
+
// the border. Only the sides where edges come in get it.
|
|
178
|
+
const entering = new Map();
|
|
179
|
+
for (const route of routes) {
|
|
180
|
+
const end = route.points[route.points.length - 1];
|
|
181
|
+
const before = route.points[route.points.length - 2];
|
|
182
|
+
if (!route.arrow || !route.ends || !end || !before || Math.abs(end[1] - before[1]) >= 0.5)
|
|
183
|
+
continue;
|
|
184
|
+
const source = elements.get(route.ends[0]);
|
|
185
|
+
const target = elements.get(route.ends[1]);
|
|
186
|
+
let group = (target?.matches(".diagram-group") ? target.parentElement : target)?.closest(".diagram-group");
|
|
187
|
+
while (group && !(source && group.contains(source))) {
|
|
188
|
+
entering.set(group, (entering.get(group) ?? new Set()).add(end[0] > before[0] ? "left" : "right"));
|
|
189
|
+
group = group.parentElement?.closest(".diagram-group");
|
|
190
|
+
}
|
|
120
191
|
}
|
|
121
|
-
|
|
122
|
-
for (const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
192
|
+
let moved = false;
|
|
193
|
+
for (const group of groups) {
|
|
194
|
+
const sides = [...(entering.get(group) ?? [])].sort().join(" ");
|
|
195
|
+
if ((group.getAttribute("data-entry") ?? "") === sides)
|
|
196
|
+
continue;
|
|
197
|
+
if (sides)
|
|
198
|
+
group.setAttribute("data-entry", sides);
|
|
199
|
+
else
|
|
200
|
+
group.removeAttribute("data-entry");
|
|
201
|
+
moved = true;
|
|
202
|
+
}
|
|
203
|
+
// The room moved the nodes, so measure again; a second pass settles.
|
|
204
|
+
if (moved && pass < 2)
|
|
205
|
+
return layout(pass + 1);
|
|
206
|
+
const frames = groups.map((element) => ({
|
|
207
|
+
...place(element.getBoundingClientRect()),
|
|
208
|
+
radius: parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0,
|
|
209
|
+
}));
|
|
210
|
+
// Labels are measured once and kept, since measuring makes the page lay
|
|
211
|
+
// out again. New labels are measured in one batch: the probes go in
|
|
212
|
+
// together and are read together. A loaded font clears what was kept.
|
|
213
|
+
const sizes = labelSizes.current;
|
|
214
|
+
const host = svg.current;
|
|
215
|
+
if (host) {
|
|
216
|
+
const probes = [...new Set(routes.flatMap((item) => item.label && !sizes.has(item.label.text) ? [item.label.text] : []))].map((text) => {
|
|
217
|
+
const probe = document.createElementNS("http://www.w3.org/2000/svg", "text");
|
|
218
|
+
probe.setAttribute("class", "diagram-edge-label");
|
|
219
|
+
probe.textContent = text;
|
|
220
|
+
host.appendChild(probe);
|
|
221
|
+
return [text, probe];
|
|
138
222
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
223
|
+
for (const [text, probe] of probes) {
|
|
224
|
+
const { width, height } = probe.getBBox();
|
|
225
|
+
sizes.set(text, { width, height });
|
|
226
|
+
}
|
|
227
|
+
for (const [, probe] of probes)
|
|
228
|
+
probe.remove();
|
|
142
229
|
}
|
|
143
|
-
|
|
230
|
+
const measure = (text) => sizes.get(text) ?? { width: text.length * 7, height: 12 };
|
|
231
|
+
setDrawn(draw(routes, frames, crossings, labels, measure, { shape, arrow, boxes: new Map(all.map((item) => [item.id, item])) }));
|
|
144
232
|
};
|
|
233
|
+
const measure = () => layout(0);
|
|
145
234
|
measure();
|
|
146
235
|
const observer = new ResizeObserver(measure);
|
|
147
236
|
observer.observe(root);
|
|
148
237
|
observer.observe(region);
|
|
149
238
|
nodes.forEach((element) => observer.observe(element));
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
239
|
+
const fonts = typeof document !== "undefined" ? document.fonts : undefined;
|
|
240
|
+
const refont = () => {
|
|
241
|
+
labelSizes.current.clear();
|
|
242
|
+
measure();
|
|
243
|
+
};
|
|
244
|
+
fonts?.addEventListener("loadingdone", refont);
|
|
245
|
+
return () => {
|
|
246
|
+
observer.disconnect();
|
|
247
|
+
fonts?.removeEventListener("loadingdone", refont);
|
|
248
|
+
};
|
|
249
|
+
}, [direction, crossings, labels, shape, arrow, registered, nodes, version]);
|
|
250
|
+
return (_jsx(DiagramContext.Provider, { value: context, children: _jsxs("div", { ...props, "data-slot": "diagram", className: cn("card diagram", className), "data-direction": direction, "data-background-style": background, "data-background-strength": strength, children: [_jsx("div", { ref: scroll, "data-slot": "diagram-scroll", className: "diagram-scroll", role: "group", "aria-label": label, tabIndex: 0, children: _jsxs("div", { ref: frame, "data-slot": "diagram-canvas", className: "diagram-canvas", children: [_jsx("div", { ref: lanes, "data-slot": "diagram-lanes", className: "diagram-lanes", "data-direction": direction, style: direction === "grid" && columns ? { "--diagram-columns": columns } : undefined, "data-border-style": borderStyle, "data-corner-style": cornerStyle, "data-corner-size": cornerSize, "data-corner-marks": cornerMarks, "data-edge-labels": registered.some((edge) => edge.label) || undefined, children: children }), _jsxs("svg", { ref: svg, className: "diagram-edges", "aria-hidden": "true", children: [_jsxs("defs", { children: [["neutral", "success", "danger"].map((tone) => (_jsx("marker", { id: `${marker}-${tone}`, className: "diagram-arrow", "data-tone": tone, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M 0 0 L 10 5 L 0 10 z" }) }, tone))), [...new Set(registered.flatMap((edge) => edge.series ? [edge.series] : []))].map((series) => (_jsx("marker", { id: `${marker}-s${series}`, className: "diagram-arrow", style: { color: chartColor(series) }, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "6", markerHeight: "6", orient: "auto-start-reverse", children: _jsx("path", { d: "M 0 0 L 10 5 L 0 10 z" }) }, series))), [...new Set(drawn.paths.flatMap((path) => path.arrow && path.head !== "triangle" && path.head !== "none"
|
|
251
|
+
? [`${path.head}|${path.series ? `s${path.series}` : path.tone ?? "neutral"}`] : []))].map((id) => {
|
|
252
|
+
const [head, paint] = id.split("|");
|
|
253
|
+
const series = paint.startsWith("s") ? Number(paint.slice(1)) : undefined;
|
|
254
|
+
const size = series ? "6" : "7";
|
|
255
|
+
return (_jsx("marker", { id: `${marker}-${head}-${paint}`, className: "diagram-arrow", "data-arrow": head, "data-tone": series ? undefined : paint, style: series ? { color: chartColor(series) } : undefined, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: size, markerHeight: size, orient: "auto-start-reverse", children: heads[head] }, id));
|
|
256
|
+
})] }), drawn.plates.map((plate) => (_jsx("rect", { className: "diagram-edge-plate", x: plate.x, y: plate.y, width: plate.width, height: plate.height }, plate.key))), drawn.paths.map((path) => {
|
|
257
|
+
const series = path.series;
|
|
258
|
+
const paint = series ? `s${series}` : path.tone ?? "neutral";
|
|
259
|
+
return (_jsxs(React.Fragment, { children: [path.knock && _jsx("path", { className: "diagram-edge-knock", d: path.knock }), _jsx("path", { d: path.d, "data-shape": path.shape && path.shape !== "orthogonal" ? path.shape : undefined, "data-line": series ? undefined : path.line, "data-tone": series ? undefined : path.tone, "data-series": series, "data-dash": series ? dashOf(series) : undefined, "data-flow": (series && path.flow) || undefined, style: series ? { color: chartColor(series) } : undefined, markerEnd: !path.arrow || path.head === "none" ? undefined : `url(#${marker}-${path.head === "triangle" ? "" : `${path.head}-`}${paint})` })] }, path.key));
|
|
260
|
+
}), drawn.dots.map((dot) => (_jsx("circle", { className: "diagram-junction", cx: dot.x, cy: dot.y, r: "3", "data-tone": dot.series ? undefined : dot.tone, style: dot.series ? { color: chartColor(dot.series) } : undefined }, dot.key))), drawn.labels.map((item) => (_jsxs(React.Fragment, { children: [item.plate && _jsx("rect", { className: "diagram-edge-plate", x: item.plate.x, y: item.plate.y, width: item.plate.width, height: item.plate.height }), _jsx("text", { x: item.x, y: item.y, className: "diagram-edge-label", "data-anchor": item.anchor, "data-orient": item.rotate ? "vertical" : item.middle ? "inline" : undefined, transform: item.rotate ? `rotate(-90 ${item.x} ${item.y})` : undefined, children: item.lines.length > 1
|
|
261
|
+
? _jsxs(_Fragment, { children: [_jsx("tspan", { x: item.x, dy: "-1.2em", children: item.lines[0] }), _jsx("tspan", { x: item.x, dy: "1.2em", children: item.lines[1] })] })
|
|
262
|
+
: item.lines[0] })] }, item.key)))] })] }) }), footer != null && (_jsx("div", { "data-slot": "diagram-footer", className: "diagram-footer", children: _jsx("div", { className: "diagram-footer-items", children: footer }) }))] }) }));
|
|
153
263
|
}
|
|
264
|
+
/* A stage of a Diagram read left to right. */
|
|
154
265
|
function DiagramColumn({ className, ...props }) {
|
|
155
|
-
return _jsx("div", { ...props, "data-slot": "diagram-column", className: cn("diagram-column", className) });
|
|
266
|
+
return _jsx("div", { ...props, "data-slot": "diagram-column", className: cn("diagram-stage diagram-column", className) });
|
|
267
|
+
}
|
|
268
|
+
/* A stage of a Diagram read top to bottom: nodes side by side. The rows
|
|
269
|
+
share the width of the widest one, so `justify` can put a node under the
|
|
270
|
+
one it hangs from without a layout engine. */
|
|
271
|
+
function DiagramRow({ justify, className, ...props }) {
|
|
272
|
+
return _jsx("div", { ...props, "data-slot": "diagram-row", className: cn("diagram-stage diagram-row", className), "data-justify": justify });
|
|
273
|
+
}
|
|
274
|
+
/* A frame around one or more nodes, each still its own card, or around
|
|
275
|
+
other groups, with its name on the top border, a line and a colour.
|
|
276
|
+
Edges reach each node inside it. A DiagramNodeGroup is one card split by
|
|
277
|
+
rules; a DiagramGroup is a frame around cards. */
|
|
278
|
+
/* A collapsible group folds to one line: the title stays on the border, its
|
|
279
|
+
nodes show only their icon and title side by side, and edges to those
|
|
280
|
+
nodes reach the frame instead. The footer leaves while folded. The nodes
|
|
281
|
+
stay mounted, so they keep their state. */
|
|
282
|
+
function DiagramGroup({ label, title, footer, line, tone, collapsible = false, defaultOpen = true, className, style, children, ...props }) {
|
|
283
|
+
const name = React.useId();
|
|
284
|
+
const body = React.useId();
|
|
285
|
+
const registry = React.useContext(DiagramContext);
|
|
286
|
+
const [open, setOpen] = React.useState(defaultOpen);
|
|
287
|
+
// Folded, the frame keeps its size across the flow and gives up the rest,
|
|
288
|
+
// like a DiagramFold, so the stages beside it do not move: top to bottom
|
|
289
|
+
// and in a grid it keeps its width, left to right its height. The size
|
|
290
|
+
// belongs to the layout it was measured in; in another layout the folded
|
|
291
|
+
// frame takes its natural size.
|
|
292
|
+
const [size, setSize] = React.useState();
|
|
293
|
+
const kept = size && size.direction === registry?.direction
|
|
294
|
+
? size.direction === "right" ? { minBlockSize: size.height } : { inlineSize: size.width }
|
|
295
|
+
: undefined;
|
|
296
|
+
const frame = React.useRef(null);
|
|
297
|
+
const shown = !collapsible || open;
|
|
298
|
+
const text = _jsxs(_Fragment, { children: [label && _jsxs(_Fragment, { children: [_jsx("span", { className: "t-caps", children: label }), _jsx("span", { "aria-hidden": "true", children: "\u00B7" })] }), _jsx("strong", { children: title })] });
|
|
299
|
+
const Chevron = open ? ChevronUp : ChevronDown;
|
|
300
|
+
return (_jsxs("div", { ref: frame, role: "group", "aria-labelledby": name, ...props, "data-slot": "diagram-group", className: cn("diagram-group", className), "data-line": line, "data-tone": tone, "data-open": collapsible ? open : undefined, style: !shown && kept ? { ...style, ...kept } : style, children: [_jsx("span", { className: "diagram-group-title", children: collapsible ? (_jsxs("button", { type: "button", id: name, className: "diagram-group-toggle", "aria-expanded": open, "aria-controls": body, onClick: () => {
|
|
301
|
+
const rect = frame.current?.getBoundingClientRect();
|
|
302
|
+
if (open && rect)
|
|
303
|
+
setSize({ direction: registry?.direction, width: rect.width, height: rect.height });
|
|
304
|
+
setOpen(!open);
|
|
305
|
+
registry?.refresh();
|
|
306
|
+
}, children: [text, _jsx(Chevron, { className: "icon icon-sm", strokeWidth: 1.75, "aria-hidden": "true", focusable: "false" })] })) : _jsx("span", { id: name, className: "diagram-group-name", children: text }) }), _jsx("div", { id: body, className: "diagram-group-body", children: children }), footer != null && shown && _jsx("div", { className: "diagram-group-foot", children: footer })] }));
|
|
156
307
|
}
|
|
157
308
|
/* A group draws several nodes as one card, split by a rule, such as the
|
|
158
309
|
container that receives requests with the other containers under it.
|
|
@@ -211,11 +362,16 @@ function DiagramLine({ end, onClick, className, children, ...props }) {
|
|
|
211
362
|
}
|
|
212
363
|
/* An edge renders nothing itself: it registers with the Diagram, which draws
|
|
213
364
|
it once the nodes are measured. */
|
|
214
|
-
function DiagramEdge({ from, to, label, line, tone }) {
|
|
365
|
+
function DiagramEdge({ from, to, label, route, line, tone, series, flow, shape, arrow }) {
|
|
215
366
|
const { addEdge } = useRegistry("DiagramEdge");
|
|
216
367
|
// Ids never contain a newline, so the join is a stable dependency.
|
|
217
368
|
const sources = (Array.isArray(from) ? from : [from]).join("\n");
|
|
218
|
-
React.useEffect(() => addEdge({ key: `${sources}->${to}`, from: sources.split("\n"), to, label, line, tone }), [addEdge, sources, to, label, line, tone]);
|
|
369
|
+
React.useEffect(() => addEdge({ key: `${sources}->${to}${series ? `#${series}` : ""}`, from: sources.split("\n"), to, label, route, line, tone, series, flow, shape, head: arrow }), [addEdge, sources, to, label, route, line, tone, series, flow, shape, arrow]);
|
|
219
370
|
return null;
|
|
220
371
|
}
|
|
221
|
-
|
|
372
|
+
/* A sample of a series edge, its colour and dash, with what it means. The
|
|
373
|
+
product lays these out as the drawing's key; the sample never moves. */
|
|
374
|
+
function DiagramEdgeKey({ series, className, children, ...props }) {
|
|
375
|
+
return (_jsxs("span", { ...props, "data-slot": "diagram-edge-key", className: cn("diagram-edge-key", className), children: [_jsx("svg", { viewBox: "0 0 28 6", "aria-hidden": "true", focusable: "false", style: { color: chartColor(series) }, children: _jsx("path", { d: "M 2 3 H 26", "data-series": series, "data-dash": dashOf(series) }) }), children] }));
|
|
376
|
+
}
|
|
377
|
+
export { Diagram, DiagramColumn, DiagramRow, DiagramGroup, DiagramEdgeKey, DiagramNodeGroup, DiagramNode, DiagramFact, DiagramFold, DiagramFilter, DiagramSection, DiagramLine, DiagramEdge };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./card.js";
|
|
|
10
10
|
export * from "./checkbox.js";
|
|
11
11
|
export * from "./chip-input.js";
|
|
12
12
|
export * from "./code-block.js";
|
|
13
|
+
export * from "./combobox.js";
|
|
13
14
|
export * from "./code-editor.js";
|
|
14
15
|
export * from "./filter-input.js";
|
|
15
16
|
export * from "./filter-expression.js";
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./card.js";
|
|
|
11
11
|
export * from "./checkbox.js";
|
|
12
12
|
export * from "./chip-input.js";
|
|
13
13
|
export * from "./code-block.js";
|
|
14
|
+
export * from "./combobox.js";
|
|
14
15
|
export * from "./code-editor.js";
|
|
15
16
|
export * from "./filter-input.js";
|
|
16
17
|
export * from "./filter-expression.js";
|
package/dist/styles.css
CHANGED
|
@@ -292,6 +292,12 @@
|
|
|
292
292
|
}
|
|
293
293
|
[data-slot="select-viewport"] { min-height: 0; }
|
|
294
294
|
|
|
295
|
+
/* The combobox list matches the input width and fits the space Radix measures, up to 20rem. */
|
|
296
|
+
.combobox-content {
|
|
297
|
+
width: var(--radix-popover-trigger-width);
|
|
298
|
+
max-height: min(20rem, var(--radix-popover-content-available-height));
|
|
299
|
+
}
|
|
300
|
+
|
|
295
301
|
/* Portalled surfaces: above the page, never wider than it. */
|
|
296
302
|
.kiso-react-floating {
|
|
297
303
|
z-index: 70;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momoi-labs/kiso-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Kiso React components built with shadcn/ui and Radix",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepack": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@momoi-labs/kiso": "^1.
|
|
35
|
+
"@momoi-labs/kiso": "^1.3.0",
|
|
36
36
|
"class-variance-authority": "0.7.1",
|
|
37
37
|
"clsx": "2.1.1",
|
|
38
38
|
"radix-ui": "1.6.7",
|