@multiplatform.one/node-graph 7.88.3 → 7.88.5

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 (65) 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/dom/NodeGraphDomShell.ts +40 -41
  47. package/src/dom/domEntry.spec.ts +22 -11
  48. package/src/dom/importGraph.spec.ts +6 -7
  49. package/src/edges/GraphEdge.tsx +37 -6
  50. package/src/edges/edgeStyle.spec.ts +73 -13
  51. package/src/edges/edgeStyle.ts +68 -15
  52. package/src/nodes/GraphNode.tsx +27 -15
  53. package/src/nodes/Overview.stories.spec.tsx +35 -0
  54. package/src/nodes/Overview.stories.tsx +26 -11
  55. package/src/nodes/arrowheadPlacement.spec.tsx +109 -0
  56. package/src/react-flow/flowAdapter.ts +4 -7
  57. package/src/react-flow/useGraphController.spec.tsx +6 -6
  58. package/types/dom/NodeGraphDomShell.d.ts +10 -3
  59. package/types/dom/NodeGraphDomShell.d.ts.map +1 -1
  60. package/types/edges/GraphEdge.d.ts.map +1 -1
  61. package/types/edges/edgeStyle.d.ts +41 -9
  62. package/types/edges/edgeStyle.d.ts.map +1 -1
  63. package/types/nodes/GraphNode.d.ts.map +1 -1
  64. package/types/react-flow/flowAdapter.d.ts +4 -5
  65. package/types/react-flow/flowAdapter.d.ts.map +1 -1
@@ -15,9 +15,16 @@
15
15
  * top-level dependency happens before any error boundary exists. So the shell
16
16
  * imports nothing of ours at the top, stamps how far boot got on a global as
17
17
  * early as the module body allows, and only then reaches for the real tree
18
- * through a dynamic `import()` inside a try/catch. Under Metro that becomes a
19
- * `require`, so a module-eval throw is catchable and reportable instead of
20
- * fatal.
18
+ * through a `require` inside a try/catch, so a module-eval throw is catchable
19
+ * and reportable instead of fatal.
20
+ *
21
+ * A `require`, never an `import()` (FZ-9001). In a production export Metro
22
+ * splits an `import()` into a lazy chunk under `_expo/static/js/web/`, and an
23
+ * OTA update stores its assets flat in `.expo-internal/`, so on the iOS Kitchen
24
+ * Sink the chunk's URL pointed at a file that was never there and every canvas
25
+ * died with "Loading module ... NodeGraphDomInner-<hash>.js failed". A
26
+ * `require` puts the inner tree in the entry script, which is the one file the
27
+ * update store does carry.
21
28
  *
22
29
  * Two consequences worth naming, because both look like mistakes:
23
30
  *
@@ -332,48 +339,40 @@ export function NodeGraphDomShell<
332
339
  );
333
340
 
334
341
  useEffect(() => {
335
- let cancelled = false;
336
- void (async () => {
337
- try {
338
- const loaded = (await import("./NodeGraphDomInner")) as InnerModule;
339
- if (cancelled) return;
340
- // The functional form, because React would otherwise call a component
341
- // passed to `setState` as an updater.
342
- setInner(() => loaded.NodeGraphDomInner);
343
- } catch (error) {
344
- if (cancelled) return;
345
- const message = messageOf(error);
346
- setModuleError(message);
347
- // Written INLINE, not through `recordGraphError`, for the same reason
348
- // the boot stage is: this file may carry no top-level import of ours
349
- // that could itself throw (design 9.4 layer 3), and a dynamic import
350
- // inside the handler for a failed dynamic import is not a place to put
351
- // faith. `diagnostics/lastError.ts` exports the key, and
352
- // `useGraphDiagnostics.spec.tsx` asserts this literal still matches it.
353
- //
354
- // First-write-wins, matching the reader: a module-eval throw drags a
355
- // train of render errors behind it, and the cause is the one worth
356
- // reporting.
357
- const slot = globalThis as unknown as Record<string, unknown>;
358
- if (!slot.__mp_graph_error) {
359
- slot.__mp_graph_error = {
360
- phase: "module",
361
- message,
362
- stack: error instanceof Error ? error.stack : undefined,
363
- at: Date.now(),
364
- };
365
- }
366
- report({
367
- t: "error",
342
+ try {
343
+ const loaded = require("./NodeGraphDomInner") as InnerModule;
344
+ // The functional form, because React would otherwise call a component
345
+ // passed to `setState` as an updater.
346
+ setInner(() => loaded.NodeGraphDomInner);
347
+ } catch (error) {
348
+ const message = messageOf(error);
349
+ setModuleError(message);
350
+ // Written INLINE, not through `recordGraphError`, for the same reason
351
+ // the boot stage is: this file may carry no top-level import of ours
352
+ // that could itself throw (design 9.4 layer 3), and a dynamic import
353
+ // inside the handler for a failed module load is not a place to put
354
+ // faith. `diagnostics/lastError.ts` exports the key, and
355
+ // `useGraphDiagnostics.spec.tsx` asserts this literal still matches it.
356
+ //
357
+ // First-write-wins, matching the reader: a module-eval throw drags a
358
+ // train of render errors behind it, and the cause is the one worth
359
+ // reporting.
360
+ const slot = globalThis as unknown as Record<string, unknown>;
361
+ if (!slot.__mp_graph_error) {
362
+ slot.__mp_graph_error = {
368
363
  phase: "module",
369
364
  message,
370
365
  stack: error instanceof Error ? error.stack : undefined,
371
- });
366
+ at: Date.now(),
367
+ };
372
368
  }
373
- })();
374
- return () => {
375
- cancelled = true;
376
- };
369
+ report({
370
+ t: "error",
371
+ phase: "module",
372
+ message,
373
+ stack: error instanceof Error ? error.stack : undefined,
374
+ });
375
+ }
377
376
  }, [report]);
378
377
 
379
378
  if (moduleError) {
@@ -176,13 +176,24 @@ describe("NodeGraphDomShell.ts", () => {
176
176
  expect(shellSource).toMatch(/stage:\s*["']script["']/);
177
177
  });
178
178
 
179
- it("dynamic-imports NodeGraphDomInner inside a try/catch", () => {
180
- expect(shellSource).toMatch(/import\(\s*["']\.\/NodeGraphDomInner["']\s*\)/);
181
- const dynamicImportIndex = shellSource.indexOf('import("./NodeGraphDomInner")');
182
- const tryIndex = shellSource.lastIndexOf("try {", dynamicImportIndex);
183
- const catchIndex = shellSource.indexOf("catch", dynamicImportIndex);
179
+ it("requires NodeGraphDomInner inside a try/catch", () => {
180
+ const requireIndex = shellSource.indexOf('require("./NodeGraphDomInner")');
181
+ expect(requireIndex).toBeGreaterThan(-1);
182
+ const tryIndex = shellSource.lastIndexOf("try {", requireIndex);
183
+ const catchIndex = shellSource.indexOf("catch", requireIndex);
184
184
  expect(tryIndex).toBeGreaterThan(-1);
185
- expect(catchIndex).toBeGreaterThan(dynamicImportIndex);
185
+ expect(catchIndex).toBeGreaterThan(requireIndex);
186
+ });
187
+
188
+ /**
189
+ * FZ-9001. A production export splits an `import()` into a lazy chunk under
190
+ * `_expo/static/js/web/`, and an OTA update stores its assets flat in
191
+ * `.expo-internal/`, so the chunk was never there on the iOS Kitchen Sink and
192
+ * every canvas reported "Loading module ... NodeGraphDomInner-<hash>.js
193
+ * failed". Nothing on the DOM side may load lazily.
194
+ */
195
+ it("never loads the inner tree through a split chunk", () => {
196
+ expect(shellSource).not.toMatch(/\bimport\(\s*["']/);
186
197
  });
187
198
 
188
199
  it("takes the config and the schema an app's entry supplies", () => {
@@ -334,7 +345,7 @@ describe("the build --exclude pattern", () => {
334
345
  /**
335
346
  * The same pattern also matches `NodeGraphDomInner`, and that is correct
336
347
  * rather than a slip: `./dom` is pinned to source on every condition, so the
337
- * entry is loaded from `src/` and its relative `import("./NodeGraphDomInner")`
348
+ * entry is loaded from `src/` and its relative `require("./NodeGraphDomInner")`
338
349
  * resolves from `src/` too. Nothing in `dist` references the inner tree, and a
339
350
  * compiled twin of it could only shadow the source one.
340
351
  */
@@ -343,8 +354,8 @@ describe("the build --exclude pattern", () => {
343
354
  });
344
355
 
345
356
  /**
346
- * And the shell, for the same reason one step out: it holds the dynamic
347
- * `import("./NodeGraphDomInner")`, so a compiled shell in `dist` would open a
357
+ * And the shell, for the same reason one step out: it holds the
358
+ * `require("./NodeGraphDomInner")`, so a compiled shell in `dist` would open a
348
359
  * relative path to a module the build never emitted.
349
360
  */
350
361
  it("keeps the shell out of dist with it", () => {
@@ -388,9 +399,9 @@ describe("the build --exclude pattern", () => {
388
399
  const resolved = resolveRelative(file, specifier);
389
400
  if (resolved) targets.push(resolved);
390
401
  }
391
- // The dynamic import is an edge too: it is how the entry reaches the
402
+ // The shell's `require` is an edge too: it is how the entry reaches the
392
403
  // inner tree, and how the inner tree ends up in the same fate.
393
- for (const match of source.matchAll(/import\(\s*["'](\.[^"']+)["']\s*\)/g)) {
404
+ for (const match of source.matchAll(/\b(?:import|require)\(\s*["'](\.[^"']+)["']\s*\)/g)) {
394
405
  const resolved = resolveRelative(file, match[1]);
395
406
  if (resolved) targets.push(resolved);
396
407
  }
@@ -73,8 +73,8 @@ function isAllowed(specifier: string): boolean {
73
73
  const importRe =
74
74
  /(?:^|\n)\s*(?:import|export)\s[^;]*?from\s*["']([^"']+)["']|(?:^|\n)\s*import\s*["']([^"']+)["']/g;
75
75
 
76
- /** `await import("./x")` and `import("./x")`. Bare specifier only, no expressions. */
77
- const dynamicImportRe = /\bimport\s*\(\s*["']([^"']+)["']\s*\)/g;
76
+ /** `import("./x")` and `require("./x")`. Bare specifier only, no expressions. */
77
+ const dynamicImportRe = /\b(?:import|require)\s*\(\s*["']([^"']+)["']\s*\)/g;
78
78
 
79
79
  /**
80
80
  * Every specifier that puts a module in the DOM BUNDLE — static and dynamic
@@ -82,15 +82,14 @@ const dynamicImportRe = /\bimport\s*\(\s*["']([^"']+)["']\s*\)/g;
82
82
  *
83
83
  * The dynamic ones are not optional here, and reading them as optional is how
84
84
  * this spec passed while guarding almost nothing. `NodeGraphDom.ts` reaches the
85
- * entire canvas through one `await import("./NodeGraphDomInner")` (design §9.4
85
+ * entire canvas through one `require("./NodeGraphDomInner")` (design §9.4
86
86
  * layer 3), so a static-only walk visited 12 model and wire modules and never
87
87
  * saw `NodeGraphDomInner`, `NodeGraphWeb`, `xy.ts` or anything they pull. The
88
88
  * tree this boundary exists to constrain was the exact tree it could not see.
89
89
  *
90
- * Layer 3's dynamic import buys CATCHABILITY — a module-eval throw becomes a
91
- * reportable `lastError.phase === "module"` instead of a fatal — and nothing
92
- * else. Under Metro it compiles to a `require`, so the module is in the bundle
93
- * either way, and an `import.meta` inside it is still a parse error that blanks
90
+ * Layer 3's guarded `require` buys CATCHABILITY — a module-eval throw becomes
91
+ * a reportable `lastError.phase === "module"` instead of a fatal — and nothing
92
+ * else. The module is in the bundle either way, and an `import.meta` inside it is still a parse error that blanks
94
93
  * the WebView before any boundary runs. Bundling is what this walk models, so
95
94
  * bundling is what it must follow.
96
95
  */
@@ -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,35 @@
1
+ import type { ComponentType, ReactNode } from "react";
2
+ import { cleanup, screen } from "@testing-library/react";
3
+ import { renderWithProviders } from "@multiplatform.one/test-utils";
4
+ import { afterEach, expect, it, vi } from "vitest";
5
+
6
+ vi.mock("../native/DomOnlyStory", () => ({ hasDomRealm: false }));
7
+ vi.mock("../NodeGraph", () => ({
8
+ NodeGraph: ({ children, overviewZoom }: { children?: ReactNode; overviewZoom?: number }) => (
9
+ <div data-testid="canvas" data-overview-zoom={String(overviewZoom ?? "")}>
10
+ {children}
11
+ </div>
12
+ ),
13
+ }));
14
+ vi.mock("../react-flow/NodeGraphWeb", () => ({
15
+ NodeGraphWeb: () => <div data-testid="web-canvas" />,
16
+ }));
17
+
18
+ const { main, crossover } = await import("./Overview.stories");
19
+
20
+ afterEach(cleanup);
21
+
22
+ // FZ-9001: on Hermes the story mounted `NodeGraphWeb` directly, whose `<style>`
23
+ // element took the tree down with "View config getter callback for component
24
+ // `style`". Both stories go through the platform `NodeGraph`, and the React
25
+ // Flow chrome that reads the canvas store stays off the native side.
26
+ it.each([
27
+ ["Main", main],
28
+ ["Crossover", crossover],
29
+ ])("%s renders the platform canvas with no DOM-only children on native", (_name, story) => {
30
+ const Story = story.render as ComponentType;
31
+ renderWithProviders(<Story />);
32
+ expect(screen.queryByTestId("web-canvas")).toBeNull();
33
+ const canvas = screen.getByTestId("canvas");
34
+ expect(canvas.childElementCount).toBe(0);
35
+ });