@momoi-labs/kiso-react 0.26.0 → 0.27.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/diagram-routes.d.ts +8 -2
- package/dist/diagram-routes.js +670 -406
- package/dist/diagram.d.ts +10 -5
- package/dist/diagram.js +18 -4
- package/package.json +2 -2
package/dist/diagram.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type LucideIcon } from "lucide-react";
|
|
3
3
|
import { type DiagramSeries } from "./chart-data.js";
|
|
4
|
-
import { type DiagramArrow, type DiagramCrossings, type DiagramEdgeLine, type DiagramEdgeRoute, type DiagramEdgeShape, type DiagramEdgeTone, type DiagramLabels } from "./diagram-routes.js";
|
|
5
|
-
export type { DiagramArrow, DiagramCrossings, DiagramEdgeLine, DiagramEdgeRoute, DiagramEdgeShape, DiagramEdgeTone, DiagramLabels, DiagramSeries };
|
|
4
|
+
import { type DiagramArrow, type DiagramCrossings, type DiagramEdgeLine, type DiagramEdgeRoute, type DiagramEdgeShape, type DiagramEdgeSide, type DiagramEdgeTone, type DiagramLabels } from "./diagram-routes.js";
|
|
5
|
+
export type { DiagramArrow, DiagramCrossings, DiagramEdgeLine, DiagramEdgeRoute, DiagramEdgeShape, DiagramEdgeSide, DiagramEdgeTone, DiagramLabels, DiagramSeries };
|
|
6
6
|
export type DiagramKind = "route" | "service" | "repository" | "image" | "database";
|
|
7
7
|
export type DiagramBackground = "solid" | "dots" | "grid" | "crosses" | "construction" | "guides" | "fibers";
|
|
8
8
|
export type DiagramStatus = "stopped" | "failed";
|
|
@@ -145,9 +145,14 @@ export type DiagramEdgeProps = {
|
|
|
145
145
|
to: string;
|
|
146
146
|
/** Mono text on the run into the target, such as a port or a variable. */
|
|
147
147
|
label?: string;
|
|
148
|
-
/**
|
|
149
|
-
|
|
148
|
+
/** Forces the path the edge would otherwise pick, relative to the flow:
|
|
149
|
+
`side`, `down` or `drop`. `fromSide` and `toSide` win over it. */
|
|
150
150
|
route?: DiagramEdgeRoute;
|
|
151
|
+
/** The side of the source the edge leaves by. Without it, the Diagram
|
|
152
|
+
picks the side with the shortest clear path. */
|
|
153
|
+
fromSide?: DiagramEdgeSide;
|
|
154
|
+
/** The side of the target the edge comes into. */
|
|
155
|
+
toSide?: DiagramEdgeSide;
|
|
151
156
|
/** Overrides the Diagram's `edges` for this edge. */
|
|
152
157
|
shape?: DiagramEdgeShape;
|
|
153
158
|
/** Overrides the Diagram's `arrow` for this edge. */
|
|
@@ -167,7 +172,7 @@ export type DiagramEdgeProps = {
|
|
|
167
172
|
line?: never;
|
|
168
173
|
tone?: never;
|
|
169
174
|
});
|
|
170
|
-
declare function DiagramEdge({ from, to, label, route, line, tone, series: named, flow, shape, arrow }: DiagramEdgeProps): null;
|
|
175
|
+
declare function DiagramEdge({ from, to, label, route, fromSide, toSide, line, tone, series: named, flow, shape, arrow }: DiagramEdgeProps): null;
|
|
171
176
|
export type DiagramEdgeKeyProps = Omit<React.ComponentProps<"span">, "children"> & {
|
|
172
177
|
/** A chart slot, or `"neutral"`. */
|
|
173
178
|
series: DiagramSeries;
|
package/dist/diagram.js
CHANGED
|
@@ -179,7 +179,21 @@ function Diagram({ label, direction = "right", columns, crossings = "none", labe
|
|
|
179
179
|
const rect = place(element.getBoundingClientRect());
|
|
180
180
|
return rect.width && rect.height ? [{ ...rect, id: `frame:${index}`, x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }] : [];
|
|
181
181
|
});
|
|
182
|
-
|
|
182
|
+
// A group's title on its top border and what its footer holds: no run
|
|
183
|
+
// or label crosses them.
|
|
184
|
+
const titles = groups.flatMap((element, index) => [
|
|
185
|
+
...element.querySelectorAll(":scope > .diagram-group-title, :scope > .diagram-group-foot > *"),
|
|
186
|
+
].flatMap((item, part) => {
|
|
187
|
+
const rect = place(item.getBoundingClientRect());
|
|
188
|
+
return rect.width && rect.height ? [{ ...rect, id: `title:${index}:${part}`, x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }] : [];
|
|
189
|
+
}));
|
|
190
|
+
// A label keeps off a group's whole footer, so it never reads as part of it.
|
|
191
|
+
const feet = groups.flatMap((element, index) => {
|
|
192
|
+
const foot = element.querySelector(":scope > .diagram-group-foot");
|
|
193
|
+
const rect = foot ? place(foot.getBoundingClientRect()) : null;
|
|
194
|
+
return rect?.width && rect.height ? [{ ...rect, id: `foot:${index}`, x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 }] : [];
|
|
195
|
+
});
|
|
196
|
+
const routes = route(measured, all, direction, walls, titles);
|
|
183
197
|
// An edge that comes into a group from the side needs room between
|
|
184
198
|
// the border and the node, so the line runs straight after crossing
|
|
185
199
|
// the border. Only the sides where edges come in get it.
|
|
@@ -236,7 +250,7 @@ function Diagram({ label, direction = "right", columns, crossings = "none", labe
|
|
|
236
250
|
probe.remove();
|
|
237
251
|
}
|
|
238
252
|
const measure = (text) => sizes.get(text) ?? { width: text.length * 7, height: 12 };
|
|
239
|
-
setDrawn(draw(routes, frames, crossings, labels, measure, { shape, arrow, boxes: new Map(all.map((item) => [item.id, item])) }));
|
|
253
|
+
setDrawn(draw(routes, frames, crossings, labels, measure, { shape, arrow, boxes: new Map(all.map((item) => [item.id, item])), blocks: [...titles, ...feet] }));
|
|
240
254
|
};
|
|
241
255
|
const measure = () => layout(0);
|
|
242
256
|
measure();
|
|
@@ -370,12 +384,12 @@ function DiagramLine({ end, onClick, className, children, ...props }) {
|
|
|
370
384
|
}
|
|
371
385
|
/* An edge renders nothing itself: it registers with the Diagram, which draws
|
|
372
386
|
it once the nodes are measured. */
|
|
373
|
-
function DiagramEdge({ from, to, label, route, line, tone, series: named, flow, shape, arrow }) {
|
|
387
|
+
function DiagramEdge({ from, to, label, route, fromSide, toSide, line, tone, series: named, flow, shape, arrow }) {
|
|
374
388
|
const { addEdge } = useRegistry("DiagramEdge");
|
|
375
389
|
const series = named == null ? undefined : slotOf(named);
|
|
376
390
|
// Ids never contain a newline, so the join is a stable dependency.
|
|
377
391
|
const sources = (Array.isArray(from) ? from : [from]).join("\n");
|
|
378
|
-
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]);
|
|
392
|
+
React.useEffect(() => addEdge({ key: `${sources}->${to}${series ? `#${series}` : ""}`, from: sources.split("\n"), to, label, route, fromSide, toSide, line, tone, series, flow, shape, head: arrow }), [addEdge, sources, to, label, route, fromSide, toSide, line, tone, series, flow, shape, arrow]);
|
|
379
393
|
return null;
|
|
380
394
|
}
|
|
381
395
|
/* A sample of a series edge, its colour and dash, with what it means. The
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momoi-labs/kiso-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.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.5.1",
|
|
36
36
|
"class-variance-authority": "0.7.1",
|
|
37
37
|
"clsx": "2.1.1",
|
|
38
38
|
"radix-ui": "1.6.7",
|