@slashsuite/ui-react 0.13.0 → 0.13.2
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/agent-docs/components/flow-diagram.md +1 -1
- package/dist/Button.d.ts +3 -2
- package/dist/Button.js +9 -88
- package/dist/StateMachine.js +14 -11
- package/dist/core/button.d.ts +33 -0
- package/dist/core/button.js +89 -0
- package/dist/core/control.d.ts +15 -0
- package/dist/core/control.js +14 -0
- package/dist/core/fixtures/button.d.ts +26 -0
- package/dist/core/fixtures/button.js +52 -0
- package/dist/core/fixtures/types.d.ts +13 -0
- package/dist/core/fixtures/types.js +10 -0
- package/dist/core/focus.d.ts +7 -0
- package/dist/core/focus.js +7 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +12 -0
- package/dist/core/parity.d.ts +22 -0
- package/dist/core/parity.js +53 -0
- package/dist/core/themeNative.d.ts +62 -0
- package/dist/core/themeNative.js +290 -0
- package/dist/cx.d.ts +1 -8
- package/dist/cx.js +2 -8
- package/dist/density.d.ts +2 -2
- package/dist/density.js +3 -11
- package/dist/flowLayout.d.ts +4 -4
- package/dist/flowLayout.js +65 -46
- package/dist/flowRoute.d.ts +42 -0
- package/dist/flowRoute.js +238 -0
- package/dist/focus.d.ts +2 -0
- package/dist/focus.js +9 -0
- package/dist/stateMachineDots.d.ts +33 -1
- package/dist/stateMachineDots.js +32 -6
- package/dist/useFlowLayout.d.ts +13 -2
- package/dist/useFlowLayout.js +6 -3
- package/package.json +3 -2
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How `FlowDiagram`'s arrows are drawn round its boxes, after dagre has placed them. Internal.
|
|
3
|
+
*
|
|
4
|
+
* dagre ranks the boxes and gives each arrow a route: a point on the source, one point in every
|
|
5
|
+
* rank it passes (each clear of the boxes in that rank) and a point on the target. Drawn as square
|
|
6
|
+
* steps that turn halfway between two points, an arrow can turn inside a rank of tall boxes and run
|
|
7
|
+
* through one, and an arrow that leaves a box's side runs along its border. So this routes every
|
|
8
|
+
* arrow again, in the rank direction:
|
|
9
|
+
*
|
|
10
|
+
* - it leaves its source through the side facing its next point and enters its target through the
|
|
11
|
+
* side facing its last one, at ports spread along that side, so no two arrows share a port and
|
|
12
|
+
* none runs along a border;
|
|
13
|
+
* - it runs along the rank direction through each of dagre's points, and turns only in a gap
|
|
14
|
+
* between ranks, where no box and no arrow label is;
|
|
15
|
+
* - the turns in one gap are spread over tracks, so two runs across the same gap never lie on one
|
|
16
|
+
* line, and a gap too narrow for its tracks is widened, moving everything past it along.
|
|
17
|
+
*
|
|
18
|
+
* Every function here works in rank-down space (ranks stacked along y); a diagram ranked right is
|
|
19
|
+
* turned into it and back.
|
|
20
|
+
*/
|
|
21
|
+
/** The space between two runs across one gap, and between a run and the gap's edges. */
|
|
22
|
+
const TRACK = 8;
|
|
23
|
+
/** How far a port keeps from a box's corner, and the least space between two ports. */
|
|
24
|
+
const PORT_INSET = 12;
|
|
25
|
+
/** How far a self loop reaches past its box. */
|
|
26
|
+
const LOOP_REACH = 16;
|
|
27
|
+
const round = (n) => Math.round(n * 10) / 10;
|
|
28
|
+
/** The y ranges no box or label covers, between the first and the last. */
|
|
29
|
+
function gapsBetween(obstacles) {
|
|
30
|
+
const spans = obstacles
|
|
31
|
+
.map((r) => ({ top: r.y, bottom: r.y + r.height }))
|
|
32
|
+
.toSorted((a, b) => a.top - b.top);
|
|
33
|
+
const gaps = [];
|
|
34
|
+
let reach = Number.NEGATIVE_INFINITY;
|
|
35
|
+
for (const s of spans) {
|
|
36
|
+
if (s.top > reach && reach > Number.NEGATIVE_INFINITY)
|
|
37
|
+
gaps.push({ top: reach, bottom: s.top });
|
|
38
|
+
reach = Math.max(reach, s.bottom);
|
|
39
|
+
}
|
|
40
|
+
return gaps;
|
|
41
|
+
}
|
|
42
|
+
/** Whether a point lies past a box's middle, in the rank direction. */
|
|
43
|
+
const below = (box, p) => p.y > box.y + box.height / 2;
|
|
44
|
+
/**
|
|
45
|
+
* Where each arrow leaves and enters its boxes: on the side facing the next point along it,
|
|
46
|
+
* spread evenly over that side in the order of where the arrows head, so they do not cross there.
|
|
47
|
+
*/
|
|
48
|
+
function placePorts(boxes, edges) {
|
|
49
|
+
const ports = [];
|
|
50
|
+
edges.forEach((e, edge) => {
|
|
51
|
+
const first = e.points[1] ?? e.points[0];
|
|
52
|
+
const last = e.points.at(-2) ?? e.points.at(-1);
|
|
53
|
+
const from = boxes.get(e.from);
|
|
54
|
+
const to = boxes.get(e.to);
|
|
55
|
+
if (e.from === e.to || !first || !last || !from || !to)
|
|
56
|
+
return;
|
|
57
|
+
ports.push({
|
|
58
|
+
edge,
|
|
59
|
+
end: "from",
|
|
60
|
+
box: e.from,
|
|
61
|
+
side: below(from, first) ? "bottom" : "top",
|
|
62
|
+
toward: first.x,
|
|
63
|
+
}, { edge, end: "to", box: e.to, side: below(to, last) ? "bottom" : "top", toward: last.x });
|
|
64
|
+
});
|
|
65
|
+
const ends = edges.map(() => []);
|
|
66
|
+
const bySide = new Map();
|
|
67
|
+
for (const p of ports) {
|
|
68
|
+
const key = `${p.box}\u0000${p.side}`;
|
|
69
|
+
bySide.set(key, [...(bySide.get(key) ?? []), p]);
|
|
70
|
+
}
|
|
71
|
+
for (const group of bySide.values()) {
|
|
72
|
+
const [head] = group;
|
|
73
|
+
const box = head && boxes.get(head.box);
|
|
74
|
+
if (!head || !box)
|
|
75
|
+
continue;
|
|
76
|
+
const sorted = group.toSorted((a, b) => a.toward - b.toward || a.edge - b.edge);
|
|
77
|
+
const room = Math.max(0, box.width - 2 * PORT_INSET);
|
|
78
|
+
const step = sorted.length > 1 ? room / (sorted.length - 1) : 0;
|
|
79
|
+
sorted.forEach((p, i) => {
|
|
80
|
+
const x = sorted.length === 1
|
|
81
|
+
? Math.min(Math.max(p.toward, box.x + PORT_INSET), box.x + box.width - PORT_INSET)
|
|
82
|
+
: box.x + PORT_INSET + i * step;
|
|
83
|
+
const y = p.side === "top" ? box.y : box.y + box.height;
|
|
84
|
+
const at = ends[p.edge];
|
|
85
|
+
if (at)
|
|
86
|
+
at[p.end === "from" ? 0 : 1] = { x: round(x), y };
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return ends;
|
|
90
|
+
}
|
|
91
|
+
/** Gives each run in a gap the lowest track whose runs it does not overlap, and counts the tracks. */
|
|
92
|
+
function assignTracks(runs, gaps) {
|
|
93
|
+
const counts = Array.from({ length: gaps }, () => 0);
|
|
94
|
+
const ends = Array.from({ length: gaps }, () => []);
|
|
95
|
+
for (const run of runs.toSorted((a, b) => a.lo - b.lo)) {
|
|
96
|
+
const lanes = ends[run.gap] ?? [];
|
|
97
|
+
let track = lanes.findIndex((end) => end + TRACK <= run.lo);
|
|
98
|
+
if (track === -1)
|
|
99
|
+
track = lanes.length;
|
|
100
|
+
lanes[track] = run.hi;
|
|
101
|
+
ends[run.gap] = lanes;
|
|
102
|
+
run.track = track;
|
|
103
|
+
counts[run.gap] = Math.max(counts[run.gap] ?? 0, track + 1);
|
|
104
|
+
}
|
|
105
|
+
return counts;
|
|
106
|
+
}
|
|
107
|
+
/** The corners of a square loop out of a box's far side and back. */
|
|
108
|
+
function loop(box, points) {
|
|
109
|
+
const ys = points.map((p) => p.y);
|
|
110
|
+
const reach = Math.max(box.x + box.width + LOOP_REACH, ...points.map((p) => p.x));
|
|
111
|
+
const cy = box.y + box.height / 2;
|
|
112
|
+
const half = Math.min(box.height / 2 - 4, Math.max(8, (Math.max(...ys) - Math.min(...ys)) / 2));
|
|
113
|
+
const side = box.x + box.width;
|
|
114
|
+
return [
|
|
115
|
+
{ x: side, y: cy - half },
|
|
116
|
+
{ x: reach, y: cy - half },
|
|
117
|
+
{ x: reach, y: cy + half },
|
|
118
|
+
{ x: side, y: cy + half },
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
/** Whether three corners lie on one straight line across or along. */
|
|
122
|
+
const inLine = (a, b, c) => (a.x === b.x && b.x === c.x) || (a.y === b.y && b.y === c.y);
|
|
123
|
+
/** Drops a corner that does not turn: a repeat, or one in line with its neighbours. */
|
|
124
|
+
function tidy(points) {
|
|
125
|
+
const out = [];
|
|
126
|
+
for (const p of points) {
|
|
127
|
+
const last = out.at(-1);
|
|
128
|
+
const before = out.at(-2);
|
|
129
|
+
if (last && last.x === p.x && last.y === p.y)
|
|
130
|
+
continue;
|
|
131
|
+
if (last && before && inLine(before, last, p))
|
|
132
|
+
out[out.length - 1] = p;
|
|
133
|
+
else
|
|
134
|
+
out.push(p);
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/** The gap a step between two points turns in: the one it overlaps most, if any. */
|
|
139
|
+
function gapFor(gaps, a, b) {
|
|
140
|
+
const lo = Math.min(a.y, b.y);
|
|
141
|
+
const hi = Math.max(a.y, b.y);
|
|
142
|
+
return gaps
|
|
143
|
+
.map((g, index) => ({ index, size: Math.min(g.bottom, hi) - Math.max(g.top, lo) }))
|
|
144
|
+
.filter((g) => g.size > 0)
|
|
145
|
+
.toSorted((p, q) => q.size - p.size)[0]?.index;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* An arrow's draft corners through `via`: a step that moves across turns on a run in the gap it
|
|
149
|
+
* overlaps most (added to `runs`), or halfway along when no gap lies between its points.
|
|
150
|
+
*/
|
|
151
|
+
function draftSteps(via, gaps, runs) {
|
|
152
|
+
const [start] = via;
|
|
153
|
+
const out = start ? [start] : [];
|
|
154
|
+
for (let k = 1; k < via.length; k++) {
|
|
155
|
+
const a = via[k - 1];
|
|
156
|
+
const b = via[k];
|
|
157
|
+
if (!a || !b)
|
|
158
|
+
continue;
|
|
159
|
+
const gap = a.x === b.x ? undefined : gapFor(gaps, a, b);
|
|
160
|
+
if (a.x === b.x)
|
|
161
|
+
out.push(b);
|
|
162
|
+
else if (gap === undefined)
|
|
163
|
+
out.push({ x: a.x, y: (a.y + b.y) / 2 }, { x: b.x, y: (a.y + b.y) / 2 }, b);
|
|
164
|
+
else {
|
|
165
|
+
runs.push({ gap, lo: Math.min(a.x, b.x), hi: Math.max(a.x, b.x), track: 0 });
|
|
166
|
+
out.push({ run: runs.length - 1, a, b }, b);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Routes every arrow round the boxes and labels (rank-down space): see the file's comment. The
|
|
173
|
+
* lines come back in `edges`' order, in the space after the gaps are widened; `shift` moves a y
|
|
174
|
+
* from before into it, and `grow` is how much taller the diagram became.
|
|
175
|
+
*/
|
|
176
|
+
export function routeEdges(boxes, labels, edges) {
|
|
177
|
+
const gaps = gapsBetween([...boxes.values(), ...labels]);
|
|
178
|
+
const ends = placePorts(boxes, edges);
|
|
179
|
+
const runs = [];
|
|
180
|
+
/**
|
|
181
|
+
* Whether one of dagre's points lies beside a box or a label rather than in a gap. A point in a
|
|
182
|
+
* gap (a group's border rank) has nothing to clear, and passing through it would make the arrow
|
|
183
|
+
* turn on a track elsewhere in that gap and double back.
|
|
184
|
+
*/
|
|
185
|
+
const inRank = (p) => !gaps.some((g) => p.y > g.top && p.y < g.bottom);
|
|
186
|
+
/** Each arrow's corners, with a run's index in place of the y it turns at. */
|
|
187
|
+
const drafts = edges.map((e, i) => {
|
|
188
|
+
const box = boxes.get(e.from);
|
|
189
|
+
if (e.from === e.to)
|
|
190
|
+
return box ? loop(box, e.points) : [];
|
|
191
|
+
const [start, end] = ends[i] ?? [];
|
|
192
|
+
if (!start || !end)
|
|
193
|
+
return [...e.points];
|
|
194
|
+
return draftSteps([start, ...e.points.slice(1, -1).filter(inRank), end], gaps, runs);
|
|
195
|
+
});
|
|
196
|
+
const tracks = assignTracks(runs, gaps.length);
|
|
197
|
+
const widen = gaps.map((g, i) => Math.max(0, ((tracks[i] ?? 0) + 1) * TRACK - (g.bottom - g.top)));
|
|
198
|
+
const shift = (y) => y + gaps.reduce((sum, g, i) => sum + (y > g.top + 0.01 ? (widen[i] ?? 0) : 0), 0);
|
|
199
|
+
const trackY = (run) => {
|
|
200
|
+
const g = gaps[run.gap];
|
|
201
|
+
if (!g)
|
|
202
|
+
return 0;
|
|
203
|
+
const top = shift(g.top);
|
|
204
|
+
const height = g.bottom - g.top + (widen[run.gap] ?? 0);
|
|
205
|
+
return round(top + ((run.track + 1) * height) / ((tracks[run.gap] ?? 0) + 1));
|
|
206
|
+
};
|
|
207
|
+
/** A draft corner's points: a turn becomes its two corners on its run's track. */
|
|
208
|
+
const corners = (c) => {
|
|
209
|
+
if (!("run" in c))
|
|
210
|
+
return [{ x: c.x, y: round(shift(c.y)) }];
|
|
211
|
+
const run = runs[c.run];
|
|
212
|
+
if (!run)
|
|
213
|
+
return [];
|
|
214
|
+
const y = trackY(run);
|
|
215
|
+
return [
|
|
216
|
+
{ x: c.a.x, y },
|
|
217
|
+
{ x: c.b.x, y },
|
|
218
|
+
];
|
|
219
|
+
};
|
|
220
|
+
const lines = drafts.map((draft) => tidy(draft.flatMap(corners)));
|
|
221
|
+
return { lines, shift, grow: widen.reduce((a, b) => a + b, 0) };
|
|
222
|
+
}
|
|
223
|
+
/** The SVG path through square corners: a move, then one straight run to each next corner. */
|
|
224
|
+
export function squarePath(points) {
|
|
225
|
+
const [first, ...rest] = points;
|
|
226
|
+
if (!first)
|
|
227
|
+
return "";
|
|
228
|
+
let d = `M${first.x},${first.y}`;
|
|
229
|
+
let at = first;
|
|
230
|
+
for (const p of rest) {
|
|
231
|
+
if (p.x !== at.x && p.y !== at.y)
|
|
232
|
+
d += `V${p.y}H${p.x}`;
|
|
233
|
+
else
|
|
234
|
+
d += p.x === at.x ? `V${p.y}` : `H${p.x}`;
|
|
235
|
+
at = p;
|
|
236
|
+
}
|
|
237
|
+
return d;
|
|
238
|
+
}
|
package/dist/focus.d.ts
ADDED
package/dist/focus.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard focus ring every interactive control shares, and the same ring drawn inside the
|
|
3
|
+
* control, for one that fills a box which clips anything outside it (a table's sortable title, a
|
|
4
|
+
* scroller). `focusRing` with `-outline-offset-2` added would not do, since `outline-offset-2` comes
|
|
5
|
+
* later in the CSS and wins. Both are core's, so the native controls draw the same ring.
|
|
6
|
+
*/
|
|
7
|
+
import { FOCUS_RING, FOCUS_RING_INSET } from "./core/index.js";
|
|
8
|
+
export const focusRing = FOCUS_RING;
|
|
9
|
+
export const insetFocusRing = FOCUS_RING_INSET;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
|
-
import type { FlowLayout } from "./flowLayout.js";
|
|
2
|
+
import type { FlowLayout, FlowNodeBox } from "./flowLayout.js";
|
|
3
3
|
import type { StateMachineItem } from "./StateMachine.js";
|
|
4
4
|
/**
|
|
5
5
|
* The box items whose `state` is no state of the machine go in. Printable, since it reaches the DOM
|
|
@@ -31,6 +31,38 @@ export declare function useMoves(items: readonly StateMachineItem[], known: Read
|
|
|
31
31
|
};
|
|
32
32
|
/** How many slots a box with `count` items draws: all of them, or the first few and a `+N`; one more for "fewer" when open. */
|
|
33
33
|
export declare function slotsFor(count: number, open: boolean): number;
|
|
34
|
+
/**
|
|
35
|
+
* The rows a box reserves for its dots, whatever its count: the nine it shows (the `+N` included),
|
|
36
|
+
* or the rows of an open box's full list. A box with few or no items reserves the same rows, so
|
|
37
|
+
* its size does not depend on how many items it holds.
|
|
38
|
+
*/
|
|
39
|
+
export declare function rowsFor(slots: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* The room a box reserves under its tags for `slots` dots: the full grid's width and `rowsFor`'s
|
|
42
|
+
* height, so it is the same at 0, 1, 9 or 12 items (closed) and grows only when a box is opened.
|
|
43
|
+
*/
|
|
44
|
+
export declare function dotArea(slots: number): {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|
|
48
|
+
/** A box's tag row: one small pill's height. */
|
|
49
|
+
export declare const TAG_ROW = 20;
|
|
50
|
+
/** The gap between the tag row and the dot area (`mt-1`). */
|
|
51
|
+
export declare const TAG_GAP = 4;
|
|
52
|
+
/**
|
|
53
|
+
* The size of what a box holds under its label: its tag row, then its dot area. The layout takes
|
|
54
|
+
* it before the box can be measured (a server render), so the dots, placed up from the box's
|
|
55
|
+
* bottom, already sit under the tags and never on them.
|
|
56
|
+
*/
|
|
57
|
+
export declare function boxContentSize(slots: number): {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
};
|
|
61
|
+
/** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre, on the box's fixed grid. */
|
|
62
|
+
export declare function slotAt(box: FlowNodeBox, i: number, slots: number): {
|
|
63
|
+
left: number;
|
|
64
|
+
y: number;
|
|
65
|
+
};
|
|
34
66
|
/** What the dot layer draws from: the items in each box, the boxes' names, which boxes are open, and the moves. */
|
|
35
67
|
type DotPlaces = {
|
|
36
68
|
inBox: ReadonlyMap<string, readonly StateMachineItem[]>;
|
package/dist/stateMachineDots.js
CHANGED
|
@@ -83,13 +83,39 @@ export function slotsFor(count, open) {
|
|
|
83
83
|
return count;
|
|
84
84
|
return open ? count + 1 : LIMIT;
|
|
85
85
|
}
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
/**
|
|
87
|
+
* The rows a box reserves for its dots, whatever its count: the nine it shows (the `+N` included),
|
|
88
|
+
* or the rows of an open box's full list. A box with few or no items reserves the same rows, so
|
|
89
|
+
* its size does not depend on how many items it holds.
|
|
90
|
+
*/
|
|
91
|
+
export function rowsFor(slots) {
|
|
92
|
+
return Math.ceil(Math.max(LIMIT, slots) / COLS);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The room a box reserves under its tags for `slots` dots: the full grid's width and `rowsFor`'s
|
|
96
|
+
* height, so it is the same at 0, 1, 9 or 12 items (closed) and grows only when a box is opened.
|
|
97
|
+
*/
|
|
98
|
+
export function dotArea(slots) {
|
|
99
|
+
return { width: COLS * SLOT_W, height: rowsFor(slots) * SLOT_H };
|
|
100
|
+
}
|
|
101
|
+
/** A box's tag row: one small pill's height. */
|
|
102
|
+
export const TAG_ROW = 20;
|
|
103
|
+
/** The gap between the tag row and the dot area (`mt-1`). */
|
|
104
|
+
export const TAG_GAP = 4;
|
|
105
|
+
/**
|
|
106
|
+
* The size of what a box holds under its label: its tag row, then its dot area. The layout takes
|
|
107
|
+
* it before the box can be measured (a server render), so the dots, placed up from the box's
|
|
108
|
+
* bottom, already sit under the tags and never on them.
|
|
109
|
+
*/
|
|
110
|
+
export function boxContentSize(slots) {
|
|
111
|
+
const area = dotArea(slots);
|
|
112
|
+
return { width: area.width, height: TAG_ROW + TAG_GAP + area.height };
|
|
113
|
+
}
|
|
114
|
+
/** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre, on the box's fixed grid. */
|
|
115
|
+
export function slotAt(box, i, slots) {
|
|
116
|
+
const top = box.y + box.height - BOX_INSET - rowsFor(slots) * SLOT_H;
|
|
91
117
|
return {
|
|
92
|
-
left: box.x + box.width / 2 - (
|
|
118
|
+
left: box.x + box.width / 2 - (COLS * SLOT_W) / 2 + (i % COLS) * SLOT_W,
|
|
93
119
|
y: top + Math.floor(i / COLS) * SLOT_H + SLOT_H / 2,
|
|
94
120
|
};
|
|
95
121
|
}
|
package/dist/useFlowLayout.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { type RefObject } from "react";
|
|
2
2
|
import type { FlowEdge, FlowNode } from "./FlowDiagram.js";
|
|
3
3
|
import { type FlowDirection, type FlowLayout } from "./flowLayout.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type Size = {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* What the layout reads from a node. A caller that knows its content's size (`StateMachine`, whose
|
|
10
|
+
* boxes are a fixed size) gives it as `contentSize`, so the first layout, the one a server render
|
|
11
|
+
* shows, already has each box at its drawn size.
|
|
12
|
+
*/
|
|
13
|
+
export type SizedNode = Pick<FlowNode, "id" | "label" | "group" | "content"> & {
|
|
14
|
+
contentSize?: Size | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare function guessNode(node: SizedNode): Size;
|
|
6
17
|
export declare const nodeKey: (id: string) => string;
|
|
7
18
|
export declare const edgeKey: (index: number) => string;
|
|
8
19
|
/**
|
package/dist/useFlowLayout.js
CHANGED
|
@@ -12,15 +12,18 @@ const NODE_PAD_X = 26;
|
|
|
12
12
|
const NODE_PAD_Y = 18;
|
|
13
13
|
const NODE_LINE = 20;
|
|
14
14
|
const CONTENT_GUESS = 32;
|
|
15
|
+
/** The gap between a box's label and its content (`mt-2`). */
|
|
16
|
+
const CONTENT_GAP = 8;
|
|
15
17
|
const EDGE_CHAR = 6.6;
|
|
16
18
|
const EDGE_PAD = 8;
|
|
17
19
|
const EDGE_LINE = 16;
|
|
18
|
-
function guessNode(node) {
|
|
20
|
+
export function guessNode(node) {
|
|
19
21
|
const text = Math.ceil(node.label.length * NODE_CHAR);
|
|
20
22
|
const lines = Math.max(1, Math.ceil(text / (NODE_MAX - NODE_PAD_X)));
|
|
23
|
+
const content = node.contentSize ?? { width: 0, height: CONTENT_GUESS - CONTENT_GAP };
|
|
21
24
|
return {
|
|
22
|
-
width: Math.min(NODE_MAX, text + NODE_PAD_X),
|
|
23
|
-
height: lines * NODE_LINE + NODE_PAD_Y + (node.content == null ? 0 :
|
|
25
|
+
width: Math.min(NODE_MAX, Math.max(text, content.width) + NODE_PAD_X),
|
|
26
|
+
height: lines * NODE_LINE + NODE_PAD_Y + (node.content == null ? 0 : CONTENT_GAP + content.height),
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
29
|
const guessLabel = (label) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slashsuite/ui-react",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "UISlash React components: primitives, typography roles and a safe Markdown renderer, written against Tailwind v4 utilities. Pair with a theme from @slashsuite/themes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"components",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"./package.json": "./package.json"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
46
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && bun scripts/vendor-core.ts",
|
|
47
47
|
"typecheck": "tsc --noEmit",
|
|
48
48
|
"lint": "oxlint -c .oxlintrc.json --type-aware --deny-warnings --report-unused-disable-directives && bun ../../scripts/check-slop.ts",
|
|
49
49
|
"test": "vitest run",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"react-aria-components": "^1.22.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
+
"@slashsuite/core": "0.0.0",
|
|
60
61
|
"@testing-library/dom": "10.4.2",
|
|
61
62
|
"@testing-library/react": "16.3.3",
|
|
62
63
|
"@testing-library/user-event": "14.6.12",
|