@runtypelabs/react-flow 1.0.39 → 1.0.41

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.
@@ -1,8 +1,5 @@
1
1
  import type { RuntypeNode, RuntypeEdge } from '../types'
2
2
 
3
- // ============================================================================
4
- // Layout Constants
5
- // ============================================================================
6
3
 
7
4
  const DEFAULT_NODE_WIDTH = 280
8
5
  const DEFAULT_NODE_HEIGHT = 150
@@ -10,9 +7,6 @@ const HORIZONTAL_SPACING = 100
10
7
  const VERTICAL_SPACING = 80
11
8
  const BRANCH_OFFSET = 350
12
9
 
13
- // ============================================================================
14
- // Auto Layout Algorithm
15
- // ============================================================================
16
10
 
17
11
  export interface LayoutOptions {
18
12
  /** Direction of the flow */
@@ -47,7 +41,6 @@ export function autoLayout(
47
41
  branchOffset = BRANCH_OFFSET,
48
42
  } = options
49
43
 
50
- // Build adjacency map from edges
51
44
  const adjacencyMap = new Map<string, string[]>()
52
45
  const incomingMap = new Map<string, string[]>()
53
46
 
@@ -59,25 +52,20 @@ export function autoLayout(
59
52
  incomingMap.set(edge.target, [...incoming, edge.source])
60
53
  }
61
54
 
62
- // Find root nodes (nodes with no incoming edges)
63
55
  const rootNodes = nodes.filter((node) => {
64
56
  const incoming = incomingMap.get(node.id)
65
57
  return !incoming || incoming.length === 0
66
58
  })
67
59
 
68
- // If no root nodes found, use the first node
69
60
  if (rootNodes.length === 0 && nodes.length > 0) {
70
61
  rootNodes.push(nodes[0])
71
62
  }
72
63
 
73
- // Track positioned nodes
74
64
  const positionedNodes = new Map<string, { x: number; y: number }>()
75
65
  const visited = new Set<string>()
76
66
 
77
- // Position nodes using BFS
78
67
  const queue: Array<{ nodeId: string; x: number; y: number; depth: number }> = []
79
68
 
80
- // Start with root nodes
81
69
  let startX = startPosition.x
82
70
  for (const rootNode of rootNodes) {
83
71
  queue.push({ nodeId: rootNode.id, x: startX, y: startPosition.y, depth: 0 })
@@ -92,20 +80,16 @@ export function autoLayout(
92
80
 
93
81
  positionedNodes.set(nodeId, { x, y })
94
82
 
95
- // Get children
96
83
  const children = adjacencyMap.get(nodeId) || []
97
84
  const node = nodes.find((n) => n.id === nodeId)
98
85
 
99
- // Check if this is a conditional node
100
86
  const isConditional = node?.data.step.type === 'conditional'
101
87
 
102
88
  if (isConditional && children.length > 0) {
103
- // Position conditional branches side by side
104
89
  const trueBranch = children.filter((c) => c.includes('-true-'))
105
90
  const falseBranch = children.filter((c) => c.includes('-false-'))
106
91
  const normalChildren = children.filter((c) => !c.includes('-true-') && !c.includes('-false-'))
107
92
 
108
- // Position true branch to the right
109
93
  let trueY = y + nodeHeight + verticalSpacing
110
94
  for (const childId of trueBranch) {
111
95
  if (!visited.has(childId)) {
@@ -119,7 +103,6 @@ export function autoLayout(
119
103
  }
120
104
  }
121
105
 
122
- // Position false branch to the left
123
106
  let falseY = y + nodeHeight + verticalSpacing
124
107
  for (const childId of falseBranch) {
125
108
  if (!visited.has(childId)) {
@@ -133,7 +116,6 @@ export function autoLayout(
133
116
  }
134
117
  }
135
118
 
136
- // Position normal children below
137
119
  const maxBranchY = Math.max(trueY, falseY)
138
120
  let childY = maxBranchY
139
121
  for (const childId of normalChildren) {
@@ -148,7 +130,6 @@ export function autoLayout(
148
130
  }
149
131
  }
150
132
  } else {
151
- // Position children in sequence
152
133
  let childY = y + nodeHeight + verticalSpacing
153
134
  let childX = x
154
135
 
@@ -177,7 +158,6 @@ export function autoLayout(
177
158
  }
178
159
  }
179
160
 
180
- // Apply positions to nodes
181
161
  return nodes.map((node) => {
182
162
  const position = positionedNodes.get(node.id)
183
163
  if (position) {
@@ -200,7 +180,6 @@ export function centerNodes(
200
180
  ): RuntypeNode[] {
201
181
  if (nodes.length === 0) return nodes
202
182
 
203
- // Calculate bounding box
204
183
  let minX = Infinity
205
184
  let maxX = -Infinity
206
185
  let minY = Infinity
@@ -213,13 +192,11 @@ export function centerNodes(
213
192
  maxY = Math.max(maxY, node.position.y + DEFAULT_NODE_HEIGHT)
214
193
  }
215
194
 
216
- // Calculate offset to center
217
195
  const contentWidth = maxX - minX
218
196
  const contentHeight = maxY - minY
219
197
  const offsetX = (viewportWidth - contentWidth) / 2 - minX
220
198
  const offsetY = (viewportHeight - contentHeight) / 2 - minY
221
199
 
222
- // Apply offset
223
200
  return nodes.map((node) => ({
224
201
  ...node,
225
202
  position: {
package/tsup.config.ts CHANGED
@@ -3,8 +3,6 @@ import { defineConfig } from 'tsup'
3
3
  export default defineConfig({
4
4
  entry: ['src/index.ts'],
5
5
  format: ['cjs', 'esm'],
6
- // DTS generation disabled due to React version conflicts in the monorepo
7
- // Types are exported from src/types/index.ts and can be imported directly
8
6
  dts: false,
9
7
  splitting: false,
10
8
  sourcemap: false,
@@ -1,13 +0,0 @@
1
- $ tsup
2
- CLI Building entry: src/index.ts
3
- CLI Using tsconfig: tsconfig.json
4
- CLI tsup v8.5.1
5
- CLI Using tsup config: /home/runner/actions-runner/_work/core/core/packages/react-flow/tsup.config.ts
6
- CLI Target: es2020
7
- CLI Cleaning output folder
8
- CJS Build start
9
- ESM Build start
10
- ESM dist/index.mjs 101.48 KB
11
- ESM ⚡️ Build success in 984ms
12
- CJS dist/index.js 105.53 KB
13
- CJS ⚡️ Build success in 985ms