@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.
- package/CHANGELOG.md +15 -0
- package/dist/index.js +0 -5
- package/example/CHANGELOG.md +17 -0
- package/example/package.json +1 -1
- package/example/src/App.tsx +0 -58
- package/package.json +2 -2
- package/src/components/RuntypeFlowEditor.tsx +0 -21
- package/src/components/nodes/BaseNode.tsx +4 -20
- package/src/components/nodes/CodeNode.tsx +0 -6
- package/src/components/nodes/ConditionalNode.tsx +0 -9
- package/src/components/nodes/FetchUrlNode.tsx +0 -9
- package/src/components/nodes/PromptNode.tsx +0 -6
- package/src/components/nodes/SendEmailNode.tsx +0 -7
- package/src/hooks/useFlowValidation.ts +0 -36
- package/src/hooks/useRuntypeFlow.ts +0 -42
- package/src/index.ts +0 -4
- package/src/types/index.ts +0 -18
- package/src/utils/adapter.ts +1 -53
- package/src/utils/layout.ts +0 -23
- package/tsup.config.ts +0 -2
- package/.turbo/turbo-build.log +0 -13
- package/dist/index.mjs +0 -3334
- package/example/node_modules/.bin/tsc +0 -43
- package/example/node_modules/.bin/tsserver +0 -43
- package/example/node_modules/.bin/vite +0 -43
package/src/utils/layout.ts
CHANGED
|
@@ -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,
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
$ tsup
|
|
2
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
3
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
4
|
-
[34mCLI[39m tsup v8.5.1
|
|
5
|
-
[34mCLI[39m Using tsup config: /home/runner/actions-runner/_work/core/core/packages/react-flow/tsup.config.ts
|
|
6
|
-
[34mCLI[39m Target: es2020
|
|
7
|
-
[34mCLI[39m Cleaning output folder
|
|
8
|
-
[34mCJS[39m Build start
|
|
9
|
-
[34mESM[39m Build start
|
|
10
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m101.48 KB[39m
|
|
11
|
-
[32mESM[39m ⚡️ Build success in 984ms
|
|
12
|
-
[32mCJS[39m [1mdist/index.js [22m[32m105.53 KB[39m
|
|
13
|
-
[32mCJS[39m ⚡️ Build success in 985ms
|