@multiplatform.one/node-graph 7.88.4 → 7.88.6

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.
Files changed (58) hide show
  1. package/dist/cjs/edges/GraphEdge.cjs +27 -2
  2. package/dist/cjs/edges/GraphEdge.native.js +29 -5
  3. package/dist/cjs/edges/GraphEdge.native.js.map +1 -1
  4. package/dist/cjs/edges/edgeStyle.cjs +32 -7
  5. package/dist/cjs/edges/edgeStyle.native.js +34 -6
  6. package/dist/cjs/edges/edgeStyle.native.js.map +1 -1
  7. package/dist/cjs/nodes/GraphNode.cjs +15 -5
  8. package/dist/cjs/nodes/GraphNode.native.js +15 -5
  9. package/dist/cjs/nodes/GraphNode.native.js.map +1 -1
  10. package/dist/cjs/react-flow/flowAdapter.cjs +0 -5
  11. package/dist/cjs/react-flow/flowAdapter.native.js +0 -5
  12. package/dist/cjs/react-flow/flowAdapter.native.js.map +1 -1
  13. package/dist/esm/edges/GraphEdge.mjs +29 -4
  14. package/dist/esm/edges/GraphEdge.mjs.map +1 -1
  15. package/dist/esm/edges/GraphEdge.native.js +31 -7
  16. package/dist/esm/edges/GraphEdge.native.js.map +1 -1
  17. package/dist/esm/edges/edgeStyle.mjs +30 -8
  18. package/dist/esm/edges/edgeStyle.mjs.map +1 -1
  19. package/dist/esm/edges/edgeStyle.native.js +32 -7
  20. package/dist/esm/edges/edgeStyle.native.js.map +1 -1
  21. package/dist/esm/nodes/GraphNode.mjs +17 -7
  22. package/dist/esm/nodes/GraphNode.mjs.map +1 -1
  23. package/dist/esm/nodes/GraphNode.native.js +17 -7
  24. package/dist/esm/nodes/GraphNode.native.js.map +1 -1
  25. package/dist/esm/react-flow/flowAdapter.mjs +0 -5
  26. package/dist/esm/react-flow/flowAdapter.mjs.map +1 -1
  27. package/dist/esm/react-flow/flowAdapter.native.js +0 -5
  28. package/dist/esm/react-flow/flowAdapter.native.js.map +1 -1
  29. package/dist/jsx/edges/GraphEdge.mjs +29 -4
  30. package/dist/jsx/edges/GraphEdge.mjs.map +1 -1
  31. package/dist/jsx/edges/GraphEdge.native.js +29 -5
  32. package/dist/jsx/edges/GraphEdge.native.js.map +1 -1
  33. package/dist/jsx/edges/edgeStyle.mjs +30 -8
  34. package/dist/jsx/edges/edgeStyle.mjs.map +1 -1
  35. package/dist/jsx/edges/edgeStyle.native.js +34 -6
  36. package/dist/jsx/edges/edgeStyle.native.js.map +1 -1
  37. package/dist/jsx/nodes/GraphNode.mjs +17 -7
  38. package/dist/jsx/nodes/GraphNode.mjs.map +1 -1
  39. package/dist/jsx/nodes/GraphNode.native.js +15 -5
  40. package/dist/jsx/nodes/GraphNode.native.js.map +1 -1
  41. package/dist/jsx/react-flow/flowAdapter.mjs +0 -5
  42. package/dist/jsx/react-flow/flowAdapter.mjs.map +1 -1
  43. package/dist/jsx/react-flow/flowAdapter.native.js +0 -5
  44. package/dist/jsx/react-flow/flowAdapter.native.js.map +1 -1
  45. package/package.json +7 -7
  46. package/src/edges/GraphEdge.tsx +37 -6
  47. package/src/edges/edgeStyle.spec.ts +73 -13
  48. package/src/edges/edgeStyle.ts +68 -15
  49. package/src/nodes/GraphNode.tsx +27 -15
  50. package/src/nodes/arrowheadPlacement.spec.tsx +109 -0
  51. package/src/react-flow/flowAdapter.ts +4 -7
  52. package/src/react-flow/useGraphController.spec.tsx +6 -6
  53. package/types/edges/GraphEdge.d.ts.map +1 -1
  54. package/types/edges/edgeStyle.d.ts +41 -9
  55. package/types/edges/edgeStyle.d.ts.map +1 -1
  56. package/types/nodes/GraphNode.d.ts.map +1 -1
  57. package/types/react-flow/flowAdapter.d.ts +4 -5
  58. package/types/react-flow/flowAdapter.d.ts.map +1 -1
@@ -14,7 +14,7 @@
14
14
  import { usePresetContext, useResolvedKnobs } from "@multiplatform.one/theme";
15
15
  import { defaultKnobs } from "@multiplatform.one/theme";
16
16
  import type { Animation, BorderWidth } from "@multiplatform.one/theme";
17
- import { memo } from "react";
17
+ import { memo, useId } from "react";
18
18
  import { SizableText, useTheme, View } from "tamagui";
19
19
  import {
20
20
  BaseEdge,
@@ -24,7 +24,7 @@ import {
24
24
  getStraightPath,
25
25
  } from "../react-flow/xy";
26
26
  import type { EdgeProps } from "../react-flow/xy";
27
- import { resolveEdgeStyle, themeTokenName } from "./edgeStyle";
27
+ import { edgeArrowhead, resolveEdgeStyle, themeTokenName } from "./edgeStyle";
28
28
  import type { EdgePathKind, EdgeStyle } from "./edgeStyle";
29
29
 
30
30
  export const graphEdgeType = "mpGraphEdge";
@@ -140,16 +140,47 @@ export function GraphEdgeComponent(props: EdgeProps) {
140
140
  const strokeValue = useStrokeValue(style.stroke);
141
141
  const [d, labelX, labelY] = buildEdgePath(style.path, props);
142
142
  const label = data.label ?? (typeof props.label === "string" ? props.label : undefined);
143
+ const markerId = `mp-graph-arrow-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
144
+ const ownMarker = props.markerEnd === undefined;
143
145
 
144
146
  return (
145
147
  <>
148
+ {ownMarker ? (
149
+ <defs>
150
+ <marker
151
+ id={markerId}
152
+ className="mp-graph-arrowhead"
153
+ data-graph-edge-marker={style.marker}
154
+ viewBox={edgeArrowhead.viewBox}
155
+ markerWidth={edgeArrowhead.size}
156
+ markerHeight={edgeArrowhead.size}
157
+ markerUnits="strokeWidth"
158
+ orient="auto-start-reverse"
159
+ refX={edgeArrowhead.refX}
160
+ refY={edgeArrowhead.refY}
161
+ >
162
+ <polyline
163
+ points={edgeArrowhead.points[style.marker]}
164
+ strokeLinecap="round"
165
+ strokeLinejoin="round"
166
+ style={{
167
+ stroke: `var(--mp-graph-edge-stroke, ${strokeValue})`,
168
+ strokeWidth: 1,
169
+ fill:
170
+ style.marker === "arrowclosed"
171
+ ? `var(--mp-graph-edge-stroke, ${strokeValue})`
172
+ : "none",
173
+ }}
174
+ />
175
+ </marker>
176
+ </defs>
177
+ ) : null}
146
178
  <BaseEdge
147
179
  id={props.id}
148
180
  path={d}
149
- // Already a resolved `url(#...)`: React Flow builds the marker defs
150
- // from the edges array, so the TYPE is chosen by `edgeMarkerEnd` where
151
- // the edge is built, not here.
152
- markerEnd={props.markerEnd}
181
+ // The head is drawn here, in the edge's own stroke, unless the edge
182
+ // object brought its own React Flow marker (`edgeMarkerEnd`).
183
+ markerEnd={ownMarker ? `url(#${markerId})` : props.markerEnd}
153
184
  style={{
154
185
  stroke: `var(--mp-graph-edge-stroke, ${strokeValue})`,
155
186
  strokeWidth: style.strokeWidth,
@@ -23,7 +23,10 @@ import type { GraphDocument } from "../model/index";
23
23
  import { builtinEdgeKindNames, builtinEdgeKinds } from "./edgeKinds";
24
24
  import type { BuiltinEdgeData, BuiltinEdgeKind } from "./edgeKinds";
25
25
  import {
26
+ controlEdgeWeight,
26
27
  edgeAppearances,
28
+ edgeArrowhead,
29
+ edgeArrowheadLength,
27
30
  edgeMarkerEnd,
28
31
  edgeStrokeWidth,
29
32
  edgeStrokeWidths,
@@ -36,10 +39,22 @@ const hex = /#[0-9a-f]{3,8}\b/i;
36
39
  describe("the table in design §4.4", () => {
37
40
  it("is exactly what the code carries", () => {
38
41
  expect(edgeAppearances).toEqual({
39
- flow: { path: "smoothstep", stroke: "$color9", marker: "arrowclosed" },
40
- data: { path: "bezier", stroke: "$color8", marker: "arrow" },
41
- error: { path: "smoothstep", stroke: "$red9", dash: "6 4", marker: "arrowclosed" },
42
- conditional: { path: "step", stroke: "$color8", dash: "2 4", marker: "arrow" },
42
+ flow: { path: "smoothstep", stroke: "$color9", marker: "arrowclosed", weight: "control" },
43
+ data: { path: "bezier", stroke: "$color8", marker: "arrow", weight: "value" },
44
+ error: {
45
+ path: "smoothstep",
46
+ stroke: "$red9",
47
+ dash: "6 4",
48
+ marker: "arrowclosed",
49
+ weight: "control",
50
+ },
51
+ conditional: {
52
+ path: "step",
53
+ stroke: "$color8",
54
+ dash: "2 4",
55
+ marker: "arrow",
56
+ weight: "value",
57
+ },
43
58
  });
44
59
  });
45
60
 
@@ -122,19 +137,66 @@ describe("the borderWidth knob", () => {
122
137
 
123
138
  it("reaches the resolved style", () => {
124
139
  expect(
125
- resolveEdgeStyle({ kind: "flow", borderWidth: "none", animation: "quick" }).strokeWidth,
140
+ resolveEdgeStyle({ kind: "data", borderWidth: "none", animation: "quick" }).strokeWidth,
126
141
  ).toBe(1);
127
142
  expect(
128
- resolveEdgeStyle({ kind: "flow", borderWidth: "large", animation: "quick" }).strokeWidth,
143
+ resolveEdgeStyle({ kind: "data", borderWidth: "large", animation: "quick" }).strokeWidth,
129
144
  ).toBe(3);
130
145
  });
131
146
 
132
147
  it("moves every edge kind with one flip", () => {
133
- // Stroke width is not per kind, by design §4.4's last line.
134
148
  for (const kind of builtinEdgeKindNames) {
135
- expect(resolveEdgeStyle({ kind, borderWidth: "large", animation: "quick" }).strokeWidth).toBe(
136
- 3,
137
- );
149
+ const at = (borderWidth: "none" | "large") =>
150
+ resolveEdgeStyle({ kind, borderWidth, animation: "quick" }).strokeWidth;
151
+ expect(at("large") / at("none"), kind).toBe(3);
152
+ }
153
+ });
154
+ });
155
+
156
+ describe("flow and data read apart (FZ-9012)", () => {
157
+ const stops = ["none", "small", "medium", "large"] as const;
158
+ const width = (kind: BuiltinEdgeKind, borderWidth: (typeof stops)[number]) =>
159
+ resolveEdgeStyle({ kind, borderWidth, animation: "quick" }).strokeWidth;
160
+
161
+ it("strokes a control edge controlEdgeWeight times a value edge, at every stop", () => {
162
+ for (const stop of stops) {
163
+ expect(width("flow", stop) / width("data", stop), stop).toBe(controlEdgeWeight);
164
+ expect(width("error", stop) / width("conditional", stop), stop).toBe(controlEdgeWeight);
165
+ }
166
+ });
167
+
168
+ it("keeps the gap at least half a px, so it is a measured stroke and not a shade", () => {
169
+ expect(controlEdgeWeight).toBeGreaterThanOrEqual(1.5);
170
+ for (const stop of stops) {
171
+ expect(width("flow", stop) - width("data", stop), stop).toBeGreaterThanOrEqual(0.5);
172
+ }
173
+ });
174
+
175
+ it("separates flow from data in path, stroke, marker AND weight", () => {
176
+ const flow = edgeAppearances.flow;
177
+ const data = edgeAppearances.data;
178
+ expect(flow.path).not.toBe(data.path);
179
+ expect(flow.stroke).not.toBe(data.stroke);
180
+ expect(flow.marker).not.toBe(data.marker);
181
+ expect(flow.weight).not.toBe(data.weight);
182
+ });
183
+ });
184
+
185
+ describe("the arrowhead GraphEdge draws (FZ-9012)", () => {
186
+ const xs = (points: string) => points.split(" ").map((pair) => Number(pair.split(",")[0]));
187
+
188
+ it("puts its tip on the path's end and its body behind it", () => {
189
+ expect(edgeArrowhead.refX).toBe(0);
190
+ expect(edgeArrowhead.refY).toBe(0);
191
+ for (const points of Object.values(edgeArrowhead.points)) {
192
+ expect(Math.max(...xs(points))).toBe(0);
193
+ expect(Math.min(...xs(points))).toBeLessThan(0);
194
+ }
195
+ });
196
+
197
+ it("is long enough to read at every stroke the knob gives", () => {
198
+ for (const stop of ["none", "small", "medium", "large"] as const) {
199
+ expect(edgeArrowheadLength(edgeStrokeWidth(stop)), stop).toBeGreaterThanOrEqual(3);
138
200
  }
139
201
  });
140
202
  });
@@ -197,9 +259,7 @@ describe("themeTokenName", () => {
197
259
  });
198
260
 
199
261
  describe("the marker", () => {
200
- it("matches the table, and is read where the EDGE is built", () => {
201
- // React Flow builds its marker defs from the edges array and hands the
202
- // component a resolved `url(#...)`, so `BaseEdge` cannot choose a type.
262
+ it("matches the table for a consumer building raw React Flow edges", () => {
203
263
  for (const kind of builtinEdgeKindNames) {
204
264
  expect(edgeMarkerEnd({ kind }), kind).toEqual({ type: edgeAppearances[kind].marker });
205
265
  }
@@ -5,8 +5,11 @@
5
5
  * table can be asserted without mounting anything, which is what makes
6
6
  * `edgeStyle.spec.ts` a cheap test rather than a render.
7
7
  *
8
- * Stroke width is NOT per kind (design §4.4's last line): it comes from the
9
- * `borderWidth` knob, so one flip moves every edge on the canvas. Task 1.7's
8
+ * Stroke width comes from the `borderWidth` knob, so one flip moves every edge
9
+ * on the canvas. The kind picks only a WEIGHT on top of it: control edges
10
+ * (flow, error) stroke `controlEdgeWeight` times the value edges (data,
11
+ * conditional), because a one-step shade apart the two read as one line
12
+ * (FZ-9012). Task 1.7's
10
13
  * `theme/graphVars.ts` reads `edgeStrokeWidth` from here rather than repeating
11
14
  * the ladder — §11's borderWidth row cites that file, and one ladder in two
12
15
  * places is one ladder that can drift.
@@ -17,6 +20,7 @@ import type { BuiltinEdgeKind } from "./edgeKinds";
17
20
 
18
21
  export type EdgePathKind = "bezier" | "smoothstep" | "step" | "straight";
19
22
  export type EdgeMarker = "arrow" | "arrowclosed";
23
+ export type EdgeWeight = "control" | "value";
20
24
 
21
25
  export interface EdgeAppearance {
22
26
  readonly path: EdgePathKind;
@@ -25,16 +29,30 @@ export interface EdgeAppearance {
25
29
  /** SVG `stroke-dasharray`. Absent means a solid line. */
26
30
  readonly dash?: string;
27
31
  readonly marker: EdgeMarker;
32
+ readonly weight: EdgeWeight;
28
33
  }
29
34
 
30
35
  /** Design §4.4's table, verbatim. */
31
36
  export const edgeAppearances: Readonly<Record<BuiltinEdgeKind, EdgeAppearance>> = {
32
- flow: { path: "smoothstep", stroke: "$color9", marker: "arrowclosed" },
33
- data: { path: "bezier", stroke: "$color8", marker: "arrow" },
34
- error: { path: "smoothstep", stroke: "$red9", dash: "6 4", marker: "arrowclosed" },
35
- conditional: { path: "step", stroke: "$color8", dash: "2 4", marker: "arrow" },
37
+ flow: { path: "smoothstep", stroke: "$color9", marker: "arrowclosed", weight: "control" },
38
+ data: { path: "bezier", stroke: "$color8", marker: "arrow", weight: "value" },
39
+ error: {
40
+ path: "smoothstep",
41
+ stroke: "$red9",
42
+ dash: "6 4",
43
+ marker: "arrowclosed",
44
+ weight: "control",
45
+ },
46
+ conditional: { path: "step", stroke: "$color8", dash: "2 4", marker: "arrow", weight: "value" },
36
47
  };
37
48
 
49
+ /**
50
+ * How much heavier a control edge strokes than a value edge, at every
51
+ * `borderWidth` stop. A ratio rather than a second ladder, so the knob still
52
+ * moves both together and the gap between them never closes.
53
+ */
54
+ export const controlEdgeWeight = 1.5;
55
+
38
56
  /**
39
57
  * §11: an edge is a stroke, not a border, and a 0-width edge erases the graph's
40
58
  * primary information. The theme's own border widths are 0 / hairline / 1 / 2
@@ -51,8 +69,9 @@ export const edgeStrokeWidths: Readonly<Record<BorderWidth, number>> = {
51
69
  large: 3,
52
70
  };
53
71
 
54
- export function edgeStrokeWidth(borderWidth: BorderWidth): number {
55
- return edgeStrokeWidths[borderWidth];
72
+ export function edgeStrokeWidth(borderWidth: BorderWidth, weight: EdgeWeight = "value"): number {
73
+ const base = edgeStrokeWidths[borderWidth];
74
+ return weight === "control" ? base * controlEdgeWeight : base;
56
75
  }
57
76
 
58
77
  /** The keyframes live in `css/graph.css`, which lands with task 1.7. */
@@ -63,13 +82,13 @@ function isBuiltin(name: string): name is BuiltinEdgeKind {
63
82
  }
64
83
 
65
84
  /**
66
- * The marker goes on the EDGE OBJECT, not on the rendered path.
85
+ * The marker TYPE for an edge object, for a consumer that builds React Flow
86
+ * edges and lets React Flow draw the head.
67
87
  *
68
- * React Flow builds its `<marker>` defs from the edges array and hands the
69
- * component an already-resolved `url(#...)` string, so `BaseEdge`'s `markerEnd`
70
- * is a string and cannot take a type. Measured against
71
- * `@xyflow/react` 12.11.5's `BaseEdgeProps`. So whoever BUILDS the edges — the
72
- * controller in task 1.11, or a story — reads the marker from here.
88
+ * The house canvas does not: React Flow paints its own `<marker>` defs in
89
+ * `defaultMarkerColor`, a grey that matches no edge kind, so `GraphEdge` draws
90
+ * the head itself from `resolveEdgeStyle(...).marker` in the edge's own stroke
91
+ * (`edgeArrowhead` below), and `flowAdapter` leaves `markerEnd` unset.
73
92
  */
74
93
  export function edgeMarkerEnd(input: { readonly kind: string; readonly appearance?: string }): {
75
94
  readonly type: EdgeMarker;
@@ -78,6 +97,40 @@ export function edgeMarkerEnd(input: { readonly kind: string; readonly appearanc
78
97
  return { type: edgeAppearances[isBuiltin(named) ? named : "flow"].marker };
79
98
  }
80
99
 
100
+ /**
101
+ * The arrowhead `GraphEdge` draws, in marker units. `markerUnits` is
102
+ * `strokeWidth`, so the head scales with the edge and a control edge's head is
103
+ * heavier with its line.
104
+ *
105
+ * The tip is the marker's origin (`refX` / `refY` 0) and every point runs back
106
+ * from it, so the head ends exactly where the path ends: React Flow ends a path
107
+ * at the handle box's outer edge, which is the outside of the port's ring.
108
+ */
109
+ export const edgeArrowhead = {
110
+ viewBox: "-10 -10 20 20",
111
+ size: 12.5,
112
+ refX: 0,
113
+ refY: 0,
114
+ points: {
115
+ arrow: "-5,-4 0,0 -5,4",
116
+ arrowclosed: "-5,-4 0,0 -5,4 -5,-4",
117
+ },
118
+ } as const satisfies {
119
+ viewBox: string;
120
+ size: number;
121
+ refX: number;
122
+ refY: number;
123
+ points: Record<EdgeMarker, string>;
124
+ };
125
+
126
+ /** How far the head reaches back from the tip, in px, for a stroke width. */
127
+ export function edgeArrowheadLength(strokeWidth: number): number {
128
+ const xs = edgeArrowhead.points.arrowclosed.split(" ").map((pair) => Number(pair.split(",")[0]));
129
+ const reach = Math.max(...xs) - Math.min(...xs);
130
+ const unitsPerViewBox = Number(edgeArrowhead.viewBox.split(" ")[2]);
131
+ return (reach / unitsPerViewBox) * edgeArrowhead.size * strokeWidth;
132
+ }
133
+
81
134
  export interface EdgeStyleInput {
82
135
  /** `edge.kind` from the model, not React Flow's `edge.type`. */
83
136
  readonly kind: string;
@@ -114,7 +167,7 @@ export function resolveEdgeStyle(input: EdgeStyleInput): EdgeStyle {
114
167
  return {
115
168
  path: appearance.path,
116
169
  stroke: appearance.stroke,
117
- strokeWidth: edgeStrokeWidth(input.borderWidth),
170
+ strokeWidth: edgeStrokeWidth(input.borderWidth, appearance.weight),
118
171
  strokeDasharray: appearance.dash,
119
172
  marker: appearance.marker,
120
173
  // Stopping the march is not the same as erasing the dashes: the PATTERN is
@@ -18,13 +18,12 @@
18
18
  * would stack a second forced-layout storm on the observer's.
19
19
  */
20
20
 
21
- import { transitionProps } from "@multiplatform.one/theme";
21
+ import { panelPaddingPx, transitionProps } from "@multiplatform.one/theme";
22
22
 
23
23
  import { type ReactNode, useEffect, useRef } from "react";
24
24
  import { useGraphNodeKnobs } from "../knobs/graphKnobs";
25
- import { SizableText, XStack, YStack } from "tamagui";
25
+ import { SizableText, View, XStack, YStack } from "tamagui";
26
26
  import { useUpdateNodeInternals } from "../react-flow/xy";
27
- import { paintedPortSize } from "./handleGeometry";
28
27
  import { detailOpacity, isOverview } from "./lod";
29
28
  import type { GraphRenderMode } from "./lod";
30
29
  import {
@@ -104,10 +103,12 @@ export function GraphNode({
104
103
 
105
104
  const size = graphNodeSize(knobProps.sizeToken);
106
105
  const portSpacingPx = portSpacing({ coarsePointer });
107
- // The dot straddles the row's edge, so half of it lands inside the row. The
108
- // label clears the whole diameter rather than the half it strictly needs, so
109
- // the gutter still reads as a gutter at the `large` stop.
110
- const portGutterPx = paintedPortSize(size);
106
+ // §7.1 H6: the disc sits ON the frame edge. Each port mounts in a
107
+ // zero-width anchor offset back out through the frame's padding, so React
108
+ // Flow's `left: 0` / `right: 0` lands on the edge while the label keeps its
109
+ // place. Inset by the padding, every arrowhead ended on the node body and
110
+ // the body painted over it (FZ-9012).
111
+ const framePaddingPx = panelPaddingPx();
111
112
  const width = graphNodeWidth({ size, measure });
112
113
  const minHeight = graphNodeMinHeight({ size, ports: ports ?? [], portSpacingPx, measure });
113
114
  // The px the frame paints, read off the SAME fragment it is styled from.
@@ -206,14 +207,25 @@ export function GraphNode({
206
207
  // The row is where the port's painted disc overhangs the frame.
207
208
  overflow="visible"
208
209
  >
209
- {renderPort?.(port)}
210
- <SizableText
211
- {...knobProps.body}
212
- {...knobProps.label}
213
- numberOfLines={1}
214
- paddingLeft={port.side === "right" ? 0 : portGutterPx}
215
- paddingRight={port.side === "right" ? portGutterPx : 0}
216
- >
210
+ {renderPort && (port.side === "top" || port.side === "bottom")
211
+ ? renderPort(port)
212
+ : null}
213
+ {renderPort && (port.side === "left" || port.side === "right") ? (
214
+ <View
215
+ data-graph-node-port-anchor={port.side}
216
+ position="absolute"
217
+ top={0}
218
+ bottom={0}
219
+ width={0}
220
+ {...(port.side === "right"
221
+ ? { right: -framePaddingPx }
222
+ : { left: -framePaddingPx })}
223
+ overflow="visible"
224
+ >
225
+ {renderPort(port)}
226
+ </View>
227
+ ) : null}
228
+ <SizableText {...knobProps.body} {...knobProps.label} numberOfLines={1}>
217
229
  {port.label ?? port.id}
218
230
  </SizableText>
219
231
  </XStack>
@@ -0,0 +1,109 @@
1
+ /**
2
+ * FZ-9012. Every arrowhead ends at the target port's outer edge, outside its
3
+ * ring AND outside the node body.
4
+ *
5
+ * React Flow ends a path at the handle box's outer edge (`getHandlePosition`,
6
+ * `center: false`), and `GraphEdge` draws the head back from that point
7
+ * (`edgeArrowhead`). Edges paint UNDER nodes, so a head that lands inside the
8
+ * frame is painted over by the node's own surface. That is what happened while
9
+ * the port rows sat inside the frame's padding: the disc centred `padding` px
10
+ * in from the edge, and the head fell on the node body.
11
+ *
12
+ * happy-dom does no layout, so the port centre is summed from the emitted
13
+ * declarations: the frame's left border and padding, plus the port anchor's
14
+ * `left` offset. `handleGeometry.portGeometry` gives the handle box around it.
15
+ */
16
+
17
+ import { panelPaddingPx, Preset, Surface, useResolvedKnobs } from "@multiplatform.one/theme";
18
+ import { renderWithProviders } from "@multiplatform.one/test-utils";
19
+ import { cleanup } from "@testing-library/react";
20
+ import { afterEach, describe, expect, it, vi } from "vitest";
21
+ import { declarationFor } from "../../tests/styles";
22
+ import { edgeArrowheadLength, edgeStrokeWidth } from "../edges/edgeStyle";
23
+ import type { GraphNodePort } from "./nodeMeasure";
24
+ import { paintedPortSizePx, portGeometry } from "./handleGeometry";
25
+
26
+ vi.mock("../react-flow/xy", async (importOriginal) => {
27
+ const actual = await importOriginal<typeof import("../react-flow/xy")>();
28
+ return { ...actual, useUpdateNodeInternals: () => vi.fn() };
29
+ });
30
+
31
+ const { GraphNode } = await import("./GraphNode");
32
+
33
+ afterEach(cleanup);
34
+
35
+ const inPort: GraphNodePort[] = [{ id: "in", side: "left", direction: "in", label: "rows" }];
36
+
37
+ function renderNode() {
38
+ const captured = { border: 0, padding: "" };
39
+ function Probe() {
40
+ const { knobProps } = useResolvedKnobs({ component: "GraphNode" });
41
+ captured.border = Number(knobProps.surface.borderWidth ?? 0);
42
+ captured.padding = knobProps.panelPadding.padding;
43
+ return null;
44
+ }
45
+ const { container } = renderWithProviders(
46
+ <Preset cascade={false}>
47
+ <Surface size="$true">
48
+ <Probe />
49
+ <GraphNode
50
+ id="n1"
51
+ title="Sink"
52
+ ports={inPort}
53
+ renderPort={(port) => <span data-graph-port={port.id} />}
54
+ />
55
+ </Surface>
56
+ </Preset>,
57
+ );
58
+ const frame = container.querySelector("[data-graph-node]") as HTMLElement;
59
+ const anchor = container.querySelector('[data-graph-node-port-anchor="left"]');
60
+ const px = (declaration: string | undefined): number => {
61
+ if (!declaration) return 0;
62
+ const token = declaration.match(/^var\(--(?:t-)?space-(\d+)\)$/);
63
+ if (token) {
64
+ expect(`$${token[1]}`, "the frame pads by the panelPadding role").toBe(captured.padding);
65
+ return panelPaddingPx();
66
+ }
67
+ return Number.parseFloat(declaration);
68
+ };
69
+ return {
70
+ border: captured.border,
71
+ framePad: px(declarationFor(frame, "padding-left")),
72
+ anchorLeft: anchor ? px(declarationFor(anchor, "left")) : 0,
73
+ };
74
+ }
75
+
76
+ describe("FZ-9012: the arrowhead lands outside the port ring and the node body", () => {
77
+ it("centres a port on the frame's padding edge (design §7.1 H6)", () => {
78
+ const { framePad, anchorLeft } = renderNode();
79
+ expect(framePad, "the frame pads its content").toBeGreaterThan(0);
80
+ expect(framePad + anchorLeft).toBe(0);
81
+ });
82
+
83
+ it("keeps the whole head off the node body, at every port size and edge stroke", () => {
84
+ const { border, framePad, anchorLeft } = renderNode();
85
+ const centreX = border + framePad + anchorLeft;
86
+
87
+ for (const painted of Object.values(paintedPortSizePx)) {
88
+ const { box } = portGeometry({
89
+ painted,
90
+ hit: painted,
91
+ side: "left",
92
+ nodeWidth: 160,
93
+ nodeHeight: 80,
94
+ offset: 40,
95
+ });
96
+ // The path's end, and so the head's tip, for a left target: the handle
97
+ // box's left edge, which is the outside of the painted ring.
98
+ const tip = centreX + box.x;
99
+ for (const stop of ["none", "small", "medium", "large"] as const) {
100
+ for (const weight of ["value", "control"] as const) {
101
+ const tail = tip - edgeArrowheadLength(edgeStrokeWidth(stop, weight));
102
+ const label = `painted ${painted}, ${stop} ${weight}`;
103
+ expect(tip, `${label}: the tip lands on the node body`).toBeLessThan(0);
104
+ expect(tail, `${label}: the head runs into the ring`).toBeLessThan(tip);
105
+ }
106
+ }
107
+ }
108
+ });
109
+ });
@@ -2,17 +2,16 @@
2
2
  * Document → React Flow arrays. Pure, so the mapping can be asserted without
3
3
  * mounting anything.
4
4
  *
5
- * Two things happen here that cannot happen later:
5
+ * One thing happens here that cannot happen later:
6
6
  *
7
7
  * - **Size seeding (design §5).** Every node carries `width` / `height` from
8
8
  * `graphNodeMeasure` BEFORE first paint, so React Flow's per-node
9
9
  * `ResizeObserver` CORRECTS a measurement rather than discovering one. On a
10
10
  * 200-node knob flip that is the difference between 200 observer callbacks
11
11
  * resizing the world and 200 confirming it.
12
- * - **The edge marker.** `markerEnd` on the edge OBJECT, because React Flow
13
- * builds its `<marker>` defs from the edges array. Choosing it inside the
14
- * edge component is too late — measured in task 1.10, where the arrowheads
15
- * painted and the lines did not.
12
+ *
13
+ * The edge carries no `markerEnd`. React Flow would paint that head in its own
14
+ * grey; `GraphEdge` draws it in the edge's stroke instead (FZ-9012).
16
15
  */
17
16
 
18
17
  import type {
@@ -26,7 +25,6 @@ import type {
26
25
  } from "../model/index";
27
26
  import { nodeKindSpec, resolvePorts } from "../model/index";
28
27
  import { graphEdgeType } from "../edges/GraphEdge";
29
- import { edgeMarkerEnd } from "../edges/edgeStyle";
30
28
  import type { GraphNodeSizeKnob } from "../nodes/nodeMeasure";
31
29
  import { graphNodeMeasure } from "../nodes/nodeMeasure";
32
30
  import type { Edge, Node } from "./xy";
@@ -134,7 +132,6 @@ function flowEdge<N extends NodeKindDefs, E extends EdgeKindDefs>(
134
132
  sourceHandle: edge.source.port,
135
133
  target: edge.target.node,
136
134
  targetHandle: edge.target.port,
137
- markerEnd: edgeMarkerEnd({ kind: edge.kind, appearance }),
138
135
  data: { kind: edge.kind, appearance, label: edge.label },
139
136
  };
140
137
  }
@@ -584,9 +584,9 @@ describe("the React Flow arrays", () => {
584
584
  expect(edge.target).toBe("b");
585
585
  expect(edge.targetHandle).toBe("in");
586
586
  expect((edge.data as { kind?: string }).kind).toBe("flow");
587
- // The marker rides on the edge object: React Flow builds its defs from the
588
- // edges array, so choosing it in the component is too late.
589
- expect(edge.markerEnd).toBeDefined();
587
+ // No React Flow marker: its defs paint in a grey no kind uses, so
588
+ // `GraphEdge` draws the head in the edge's own stroke (FZ-9012).
589
+ expect(edge.markerEnd).toBeUndefined();
590
590
  });
591
591
 
592
592
  it("passes each node its resolved ports, not the raw kind", () => {
@@ -670,9 +670,9 @@ describe("relayout — task 4.4", () => {
670
670
  result.current.undo();
671
671
  });
672
672
 
673
- expect(result.current.document.nodes.map((node) => ({ id: node.id, ...node.position }))).toEqual(
674
- before.nodes.map((node) => ({ id: node.id, ...node.position })),
675
- );
673
+ expect(
674
+ result.current.document.nodes.map((node) => ({ id: node.id, ...node.position })),
675
+ ).toEqual(before.nodes.map((node) => ({ id: node.id, ...node.position })));
676
676
  expect(result.current.canUndo).toBe(false);
677
677
  });
678
678
 
@@ -1 +1 @@
1
- {"version":3,"file":"GraphEdge.d.ts","sourceRoot":"","sources":["../../src/edges/GraphEdge.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,aAAa,CAAC;AAE3D,eAAO,MAAM,aAAa,gBAAgB,CA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