@multiplatform.one/node-graph 7.83.2 → 7.84.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/node-graph",
3
- "version": "7.83.2",
3
+ "version": "7.84.1",
4
4
  "description": "Node graph editor — React Flow on web, Tamagui knob-aware nodes, an Expo DOM host on native",
5
5
  "keywords": [
6
6
  "multiplatform",
@@ -83,30 +83,30 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@dagrejs/dagre": "^3.1.1",
86
- "@multiplatform.one/forms": "^7.83.2",
87
- "@multiplatform.one/platform": "^7.83.2",
88
- "@multiplatform.one/theme": "^7.83.2",
86
+ "@multiplatform.one/forms": "^7.84.1",
87
+ "@multiplatform.one/platform": "^7.84.1",
88
+ "@multiplatform.one/theme": "^7.84.1",
89
89
  "@tamagui/web": "2.7.6",
90
90
  "@xyflow/react": "^12.12.0",
91
91
  "@xyflow/system": "0.0.83",
92
92
  "tamagui": "2.7.6"
93
93
  },
94
94
  "devDependencies": {
95
- "@multiplatform.one/config": "7.83.2",
96
- "@multiplatform.one/test-utils": "7.83.2",
95
+ "@multiplatform.one/config": "7.84.1",
96
+ "@multiplatform.one/test-utils": "7.84.1",
97
97
  "@tamagui/build": "2.7.6",
98
98
  "@testing-library/react": "^16.3.3",
99
99
  "@types/react-dom": "^19.2.3",
100
100
  "@vitejs/plugin-react": "^6.1.2",
101
- "@vitest/coverage-v8": "^4.1.5",
101
+ "@vitest/coverage-v8": "^4.1.12",
102
102
  "esbuild": "^0.28.2",
103
103
  "react": "19.2.5",
104
104
  "react-dom": "19.2.5",
105
105
  "subset-font": "^2.9.0",
106
- "vitest": "^4.1.5"
106
+ "vitest": "^4.1.12"
107
107
  },
108
108
  "peerDependencies": {
109
- "@multiplatform.one/components": "^7.83.2",
109
+ "@multiplatform.one/components": "^7.84.1",
110
110
  "expo": ">=55",
111
111
  "expo-haptics": "*",
112
112
  "react": "^19.1.0",
@@ -0,0 +1,48 @@
1
+ /**
2
+ * FZ-8939 (LC-18): the Edges story mounted a bare `ReactFlow`, so its pane and
3
+ * nodes painted React Flow's own dark grey (#141414, #1e1e1e) while the page
4
+ * and the edges took the tinted house ramp (Tier 2
5
+ * `nodegraph-edges--main--dark`). The lanes render through the house canvas:
6
+ * inside the graph root, under its theme vars, with house nodes.
7
+ */
8
+ import { Preset, Surface } from "@multiplatform.one/theme";
9
+ import { renderWithProviders } from "@multiplatform.one/test-utils";
10
+ import { cleanup } from "@testing-library/react";
11
+ import type { ComponentType } from "react";
12
+ import { afterEach, describe, expect, it } from "vitest";
13
+ import { graphRootClassName } from "../theme/GraphVarsStyle";
14
+ import { resetNodeCensus } from "../react-flow/nodeCensus";
15
+ import { builtinEdgeKindNames } from "./edgeKinds";
16
+ import { labels, main } from "./Edges.stories";
17
+
18
+ afterEach(() => {
19
+ cleanup();
20
+ resetNodeCensus();
21
+ });
22
+
23
+ function mount(story: { render: () => unknown }) {
24
+ const Story = story.render as ComponentType;
25
+ return renderWithProviders(
26
+ <Preset cascade={false}>
27
+ <Surface size="$true">
28
+ <Story />
29
+ </Surface>
30
+ </Preset>,
31
+ );
32
+ }
33
+
34
+ describe("NodeGraph/Edges renders on the house canvas (FZ-8939)", () => {
35
+ it.each([
36
+ ["Main", main],
37
+ ["Labels", labels],
38
+ ])("%s: the pane sits in the graph root under its theme vars, with house nodes", (_, story) => {
39
+ const { container } = mount(story);
40
+ const flow = container.querySelector(".react-flow") as HTMLElement | null;
41
+ expect(flow, "a React Flow pane").not.toBeNull();
42
+ expect(flow!.closest(`.${graphRootClassName}`), "inside the graph root").not.toBeNull();
43
+ expect(container.querySelector("style[data-mpo-graph-vars]"), "the theme vars").not.toBeNull();
44
+ const nodes = container.querySelectorAll(".react-flow__node");
45
+ expect(nodes.length).toBe(builtinEdgeKindNames.length * 2);
46
+ expect(container.querySelectorAll(".react-flow__node-default").length).toBe(0);
47
+ });
48
+ });
@@ -2,53 +2,46 @@
2
2
  * NodeGraph/Edges — the four kinds side by side, plus a refused connection with
3
3
  * its real message.
4
4
  *
5
- * The canvas mounts `ReactFlow` directly rather than `NodeGraphWeb`, which is
6
- * task 1.11's. Nodes are React Flow's own default type for the same reason:
7
- * this story is about the EDGES, and pulling in `GraphNode` (task 1.8) would
8
- * make it fail for reasons that have nothing to do with them.
5
+ * The lanes render through `NodeGraphWeb`, the canvas a consumer mounts, so the
6
+ * pane, the nodes and the edges all take the house theme (LC-18). A bare
7
+ * `ReactFlow` here painted React Flow's own grey canvas and nodes under the
8
+ * page's tinted ramp (FZ-8939).
9
9
  */
10
10
 
11
11
  import { YStack } from "tamagui";
12
- import "@xyflow/react/dist/style.css";
13
- // The package's own published stylesheet. Task 1.11's `NodeGraphWeb` imports it
14
- // for real consumers; a story that mounts `ReactFlow` directly imports it here.
15
- import "../../css/graph.css";
16
12
  import { View } from "tamagui";
17
13
  // Relative, not `@multiplatform.one/node-graph/model`: the subpath resolves
18
14
  // into `dist/`, which a source-consumed workspace package never builds.
19
15
  import { createGraphSchema, defaultRules, resolvePorts, validateConnection } from "../model/index";
16
+ import type { GraphNodeRenderProps } from "../model/index";
20
17
  import { legalTargets } from "../interaction/legalTargets";
21
- import { useKnobEnvelope } from "../knobs/useKnobEnvelope";
22
18
  import { connectionPuckLabel } from "../react-flow/ConnectionPuck";
23
19
  import { NodeGraphWeb } from "../react-flow/NodeGraphWeb";
24
20
  import { demoGraphSchema } from "../react-flow/demoNodeBody";
25
21
  import { demoDocument } from "../react-flow/fixtures";
26
22
  import type { GraphDocument } from "../model/index";
27
- import { graphEdgeType, graphEdgeTypes } from "./GraphEdge";
23
+ import { GraphNode } from "../nodes/GraphNode";
24
+ import { GraphPort } from "../nodes/GraphPort";
25
+ import type { GraphNodePort } from "../nodes/nodeMeasure";
28
26
  import { builtinEdgeKindNames, builtinEdgeKinds } from "./edgeKinds";
29
- import type { BuiltinEdgeData, BuiltinEdgeKind } from "./edgeKinds";
30
- import { edgeMarkerEnd } from "./edgeStyle";
27
+ import type { BuiltinEdgeData } from "./edgeKinds";
31
28
  import { domOnlyStoryDecorator } from "../native/DomOnlyStory";
32
- import { Position, ReactFlow, ReactFlowProvider } from "../react-flow/xy";
33
- import type { Edge, Node } from "../react-flow/xy";
34
29
  import { SizableText } from "@multiplatform.one/components";
35
30
 
36
31
  export default {
37
32
  title: "NodeGraph/Edges",
38
33
  parameters: { status: { type: "beta" } },
39
34
  /*
40
- NATIVE STOPS HERE (task 6.8). These stories mount `ReactFlow` directly —
41
- the edge kinds are the subject, so the lanes are built by hand rather than
42
- through a document — and React Flow renders `div`s and `svg`s, which React
43
- Native answers with `View config getter callback for component "div" must
44
- be a function` and a dead tree.
35
+ NATIVE STOPS HERE (task 6.8). React Flow renders `div`s and `svg`s, which
36
+ React Native answers with `View config getter callback for component "div"
37
+ must be a function` and a dead tree.
45
38
 
46
39
  The edges themselves render on device inside the canvas's WebView, which is
47
40
  what `NodeGraph → NodeGraph` shows.
48
41
  */
49
42
  decorators: [
50
43
  domOnlyStoryDecorator({
51
- needs: "mounts React Flow directly to build one lane per edge kind",
44
+ needs: "mounts the web canvas to build one lane per edge kind",
52
45
  readInstead: "NodeGraph → NodeGraph, where the same typed edges render in a real document",
53
46
  }),
54
47
  ],
@@ -56,75 +49,93 @@ export default {
56
49
 
57
50
  const rowHeight = 110;
58
51
 
59
- /** One source/target pair per kind, stacked, so all four read at once. */
60
- function laneNodes(labels: readonly string[]): Node[] {
61
- return labels.flatMap((label, row) => [
62
- {
63
- id: `s${row}`,
64
- position: { x: 0, y: row * rowHeight },
65
- data: { label },
66
- sourcePosition: Position.Right,
67
- targetPosition: Position.Left,
52
+ type LaneNode = { readonly label: string };
53
+ type LaneNodes = { readonly source: LaneNode; readonly target: LaneNode };
54
+
55
+ function LaneBody(props: GraphNodeRenderProps<LaneNode>) {
56
+ return (
57
+ <GraphNode
58
+ id={props.id}
59
+ title={props.data.label}
60
+ selected={props.selected}
61
+ dragging={props.dragging}
62
+ renderMode={props.renderMode}
63
+ measure={props.measure}
64
+ ports={props.ports as readonly GraphNodePort[]}
65
+ renderPort={(port) => <GraphPort id={port.id} side={port.side} direction={port.direction} />}
66
+ />
67
+ );
68
+ }
69
+
70
+ const laneMeasure = { width: 172, minHeight: 48 };
71
+
72
+ const laneSchema = createGraphSchema<LaneNodes, BuiltinEdgeData>({
73
+ id: "edges-story-lanes",
74
+ nodes: {
75
+ source: {
76
+ kind: "source",
77
+ render: LaneBody,
78
+ defaultData: { label: "" },
79
+ measure: laneMeasure,
80
+ ports: [{ id: "out", side: "right", direction: "out" }],
68
81
  },
69
- {
70
- id: `t${row}`,
71
- position: { x: 320, y: row * rowHeight },
72
- data: { label: "target" },
73
- sourcePosition: Position.Right,
74
- targetPosition: Position.Left,
82
+ target: {
83
+ kind: "target",
84
+ render: LaneBody,
85
+ defaultData: { label: "" },
86
+ measure: laneMeasure,
87
+ ports: [{ id: "in", side: "left", direction: "in" }],
75
88
  },
76
- ]);
77
- }
89
+ },
90
+ edges: builtinEdgeKinds,
91
+ rules: defaultRules,
92
+ });
78
93
 
79
- function laneEdge(kind: BuiltinEdgeKind, row: number, label?: string): Edge {
94
+ /** One source/target pair per kind, stacked, so all four read at once. */
95
+ function laneDocument(withLabels: boolean): GraphDocument<LaneNodes, BuiltinEdgeData> {
80
96
  return {
81
- id: `e${row}`,
82
- type: graphEdgeType,
83
- source: `s${row}`,
84
- target: `t${row}`,
85
- // The marker TYPE rides on the edge object: React Flow builds its marker
86
- // defs from the edges array.
87
- markerEnd: edgeMarkerEnd({ kind }),
88
- data: { kind, label },
97
+ version: 1,
98
+ nodes: builtinEdgeKindNames.flatMap((kind, row) => [
99
+ {
100
+ id: `s${row}`,
101
+ kind: "source" as const,
102
+ position: { x: 0, y: row * rowHeight },
103
+ data: { label: kind },
104
+ },
105
+ {
106
+ id: `t${row}`,
107
+ kind: "target" as const,
108
+ position: { x: 320, y: row * rowHeight },
109
+ data: { label: "target" },
110
+ },
111
+ ]),
112
+ edges: builtinEdgeKindNames.map((kind, row) => ({
113
+ id: `e${row}`,
114
+ kind,
115
+ source: { node: `s${row}`, port: "out" },
116
+ target: { node: `t${row}`, port: "in" },
117
+ data: {},
118
+ ...(withLabels ? { label: kind } : null),
119
+ })) as GraphDocument<LaneNodes, BuiltinEdgeData>["edges"],
89
120
  };
90
121
  }
91
122
 
92
- function Canvas({ nodes, edges }: { nodes: Node[]; edges: Edge[] }) {
93
- const envelope = useKnobEnvelope();
123
+ function Canvas({ withLabels = false }: { withLabels?: boolean }) {
94
124
  return (
95
- <View width="100%" height={rowHeight * Math.max(1, edges.length) + 60}>
96
- <ReactFlowProvider>
97
- <ReactFlow
98
- nodes={nodes}
99
- edges={edges}
100
- edgeTypes={graphEdgeTypes}
101
- colorMode={envelope.scheme}
102
- fitView
103
- proOptions={{ hideAttribution: true }}
104
- />
105
- </ReactFlowProvider>
125
+ <View width="100%" height={rowHeight * builtinEdgeKindNames.length + 60}>
126
+ <NodeGraphWeb schema={laneSchema} defaultDocument={laneDocument(withLabels)} readOnly />
106
127
  </View>
107
128
  );
108
129
  }
109
130
 
110
131
  export const main = {
111
132
  name: "Main",
112
- render: () => (
113
- <Canvas
114
- nodes={laneNodes(builtinEdgeKindNames)}
115
- edges={builtinEdgeKindNames.map((kind, row) => laneEdge(kind, row))}
116
- />
117
- ),
133
+ render: () => <Canvas />,
118
134
  };
119
135
 
120
136
  export const labels = {
121
137
  name: "Labels",
122
- render: () => (
123
- <Canvas
124
- nodes={laneNodes(builtinEdgeKindNames)}
125
- edges={builtinEdgeKindNames.map((kind, row) => laneEdge(kind, row, kind))}
126
- />
127
- ),
138
+ render: () => <Canvas withLabels />,
128
139
  };
129
140
 
130
141
  // ── Refused ────────────────────────────────────────────────────