@multiplatform.one/node-graph 7.83.1 → 7.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/node-graph",
3
- "version": "7.83.1",
3
+ "version": "7.84.0",
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",
@@ -46,7 +46,7 @@
46
46
  "types": "./types/index.d.ts",
47
47
  "import": "./dist/esm/index.mjs",
48
48
  "require": "./dist/cjs/index.cjs",
49
- "default": "./src/index.native.ts"
49
+ "default": "./dist/esm/index.mjs"
50
50
  },
51
51
  "./model": {
52
52
  "source": "./src/model/index.ts",
@@ -58,19 +58,22 @@
58
58
  "source": "./src/dom/NodeGraphDom.ts",
59
59
  "react-native": "./src/dom/NodeGraphDom.ts",
60
60
  "types": "./types/dom/NodeGraphDom.d.ts",
61
- "default": "./src/dom/NodeGraphDom.ts"
61
+ "browser": "./src/dom/NodeGraphDom.ts"
62
62
  },
63
63
  "./dom-inner": {
64
64
  "source": "./src/dom/NodeGraphDomShell.ts",
65
65
  "react-native": "./src/dom/NodeGraphDomShell.ts",
66
66
  "types": "./types/dom/NodeGraphDomShell.d.ts",
67
- "default": "./src/dom/NodeGraphDomShell.ts"
67
+ "browser": "./src/dom/NodeGraphDomShell.ts"
68
68
  },
69
69
  "./demo": {
70
70
  "source": "./src/react-flow/demoNodeBody.tsx",
71
71
  "react-native": "./src/react-flow/demoNodeBody.tsx",
72
72
  "types": "./types/react-flow/demoNodeBody.d.ts",
73
- "default": "./src/react-flow/demoNodeBody.tsx"
73
+ "browser": "./src/react-flow/demoNodeBody.tsx",
74
+ "import": "./dist/esm/react-flow/demoNodeBody.mjs",
75
+ "require": "./dist/cjs/react-flow/demoNodeBody.cjs",
76
+ "default": "./dist/esm/react-flow/demoNodeBody.mjs"
74
77
  },
75
78
  "./metro": "./metro/index.js",
76
79
  "./css/graph.css": "./css/graph.css"
@@ -80,17 +83,17 @@
80
83
  },
81
84
  "dependencies": {
82
85
  "@dagrejs/dagre": "^3.1.1",
83
- "@multiplatform.one/forms": "^7.83.1",
84
- "@multiplatform.one/platform": "^7.83.1",
85
- "@multiplatform.one/theme": "^7.83.1",
86
+ "@multiplatform.one/forms": "^7.84.0",
87
+ "@multiplatform.one/platform": "^7.84.0",
88
+ "@multiplatform.one/theme": "^7.84.0",
86
89
  "@tamagui/web": "2.7.6",
87
90
  "@xyflow/react": "^12.12.0",
88
91
  "@xyflow/system": "0.0.83",
89
92
  "tamagui": "2.7.6"
90
93
  },
91
94
  "devDependencies": {
92
- "@multiplatform.one/config": "7.83.1",
93
- "@multiplatform.one/test-utils": "7.83.1",
95
+ "@multiplatform.one/config": "7.84.0",
96
+ "@multiplatform.one/test-utils": "7.84.0",
94
97
  "@tamagui/build": "2.7.6",
95
98
  "@testing-library/react": "^16.3.3",
96
99
  "@types/react-dom": "^19.2.3",
@@ -103,7 +106,7 @@
103
106
  "vitest": "^4.1.5"
104
107
  },
105
108
  "peerDependencies": {
106
- "@multiplatform.one/components": "^7.83.1",
109
+ "@multiplatform.one/components": "^7.84.0",
107
110
  "expo": ">=55",
108
111
  "expo-haptics": "*",
109
112
  "react": "^19.1.0",
@@ -235,10 +235,11 @@ describe('package.json exports["./dom"]', () => {
235
235
  }
236
236
  });
237
237
 
238
- it("declares source, react-native and default, the three Metro can pick", () => {
238
+ it("declares source, react-native and browser for DOM bundlers", () => {
239
239
  expect(Object.keys(pkg.exports["./dom"] as object)).toEqual(
240
- expect.arrayContaining(["source", "react-native", "default"]),
240
+ expect.arrayContaining(["source", "react-native", "browser"]),
241
241
  );
242
+ expect(pkg.exports["./dom"]).not.toHaveProperty("default");
242
243
  });
243
244
  });
244
245
 
@@ -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 ────────────────────────────────────────────────────
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The package's own shape is load-bearing, so it is specced like code.
3
3
  *
4
- * Three of these four assertions are about a resolver nobody can see failing
4
+ * These assertions are about a resolver nobody can see failing
5
5
  * until a bundle breaks: Metro picks the FIRST condition it recognises and
6
6
  * never reconsiders `source` or `default` (MPO-185), and `./dom` has to stay
7
7
  * pinned to source on every condition because storybook-expo's
@@ -100,16 +100,8 @@ describe("package shape", () => {
100
100
  * `./dom-inner` is what an APP's `'use dom'` entry imports (design §9.3), so
101
101
  * it lives under the same pin as `./dom`: every runtime condition on source.
102
102
  */
103
- /**
104
- * `./demo` is pinned to source too, and for a reason neither of the others
105
- * has: it must be the SAME MODULE INSTANCE the canvas's inner tree imports.
106
- * An app's `'use dom'` entry supplies the schema by value, and a schema built
107
- * from `dist/` would carry a second copy of `GraphNode` and `GraphPort` —
108
- * Tamagui `styled()` components from a different build, rendering inside a
109
- * provider from this one. One bundle, two node implementations.
110
- */
111
- it("resolves ./dom, ./dom-inner and ./demo to a path under src/ on every condition", () => {
112
- for (const subpath of ["./dom", "./dom-inner", "./demo"]) {
103
+ it("resolves ./dom and ./dom-inner to a path under src/ on every condition", () => {
104
+ for (const subpath of ["./dom", "./dom-inner"]) {
113
105
  const leaves = targetLeaves(pkg.exports[subpath]);
114
106
  expect(leaves.length, subpath).toBeGreaterThan(0);
115
107
  for (const leaf of leaves) {
@@ -122,6 +114,36 @@ describe("package shape", () => {
122
114
  }
123
115
  });
124
116
 
117
+ /**
118
+ * `./demo` is pinned to source for bundlers: it must be the SAME MODULE
119
+ * INSTANCE the canvas's inner tree imports.
120
+ * An app's `'use dom'` entry supplies the schema by value, and a schema built
121
+ * from `dist/` would carry a second copy of `GraphNode` and `GraphPort` —
122
+ * Tamagui `styled()` components from a different build, rendering inside a
123
+ * provider from this one. One bundle, two node implementations.
124
+ */
125
+ it("resolves ./demo to the inner tree's source module under every bundler condition", () => {
126
+ const inner = "./src/react-flow/demoNodeBody.tsx";
127
+ const bundlers = {
128
+ ...metroPlatformConditions,
129
+ source: new Set(["source", "import", "require", "default"]),
130
+ };
131
+ for (const [bundler, conditions] of Object.entries(bundlers)) {
132
+ expect(metroExportTarget(pkg.exports["./demo"], conditions), bundler).toBe(inner);
133
+ }
134
+ expect(existsSync(path.join(packageRoot, inner))).toBe(true);
135
+ });
136
+
137
+ it("sends Node to the compiled ./demo", () => {
138
+ const demo = pkg.exports["./demo"];
139
+ expect(metroExportTarget(demo, new Set(["node", "import", "default"]))).toBe(
140
+ "./dist/esm/react-flow/demoNodeBody.mjs",
141
+ );
142
+ expect(metroExportTarget(demo, new Set(["node", "require", "default"]))).toBe(
143
+ "./dist/cjs/react-flow/demoNodeBody.cjs",
144
+ );
145
+ });
146
+
125
147
  it("keeps @multiplatform.one/components an optional peer, never a dependency", () => {
126
148
  expect(pkg.peerDependencies?.["@multiplatform.one/components"]).toBeDefined();
127
149
  expect(pkg.dependencies?.["@multiplatform.one/components"]).toBeUndefined();