Skip to content

Commit 4841f57

Browse files
committed
Bump reactflow version to v12
1 parent cb92677 commit 4841f57

22 files changed

+176
-337
lines changed

.storybook/preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'reactflow/dist/style.css'
1+
import '@xyflow/react/dist/style.css'
22

33
// https://storybook.js.org/docs/react/writing-stories/parameters#global-parameters
44
export const parameters = {

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.formatOnSave": true,
44
"editor.codeActionsOnSave": {
5-
"source.fixAll.eslint": true
5+
"source.fixAll.eslint": "explicit"
66
},
77
"[html]": {
88
"editor.defaultFormatter": "esbenp.prettier-vscode"

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@tisoap/react-flow-smart-edge",
3-
"version": "3.0.0",
2+
"name": "@cloudfactory/react-flow-smart-edge",
3+
"version": "1.0.0",
44
"keywords": [
55
"react",
66
"typescript",
@@ -86,6 +86,7 @@
8686
"@types/react-dom": "^18.0.9",
8787
"@typescript-eslint/eslint-plugin": "^6.6.0",
8888
"@typescript-eslint/parser": "^6.6.0",
89+
"@xyflow/react": "^12.3.5",
8990
"chromatic": "^7.1.0",
9091
"concurrently": "^8.2.1",
9192
"dts-cli": "^2.0.3",
@@ -114,7 +115,6 @@
114115
"prettier": "^3.0.3",
115116
"react": "^18.2.0",
116117
"react-dom": "^18.2.0",
117-
"reactflow": "^11.2.0",
118118
"require-from-string": "^2.0.2",
119119
"storybook": "^7.4.0",
120120
"string-width": "^4.2.3",

src/SmartBezierEdge/index.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1+
import { useNodes, BezierEdge } from '@xyflow/react'
12
import React from 'react'
2-
import { useNodes, BezierEdge } from 'reactflow'
33
import { SmartEdge } from '../SmartEdge'
44
import { svgDrawSmoothLinePath, pathfindingAStarDiagonal } from '../functions'
55
import type { SmartEdgeOptions } from '../SmartEdge'
6-
import type { EdgeProps } from 'reactflow'
6+
import type { EdgeProps, Node } from '@xyflow/react'
7+
import type {
8+
DefaultEdgeDataType,
9+
DefaultNodeDataType
10+
} from 'SmartEdge/SmartEdge.types'
711

812
const BezierConfiguration: SmartEdgeOptions = {
913
drawEdge: svgDrawSmoothLinePath,
1014
generatePath: pathfindingAStarDiagonal,
1115
fallback: BezierEdge
1216
}
1317

14-
export function SmartBezierEdge<EdgeDataType = unknown, NodeDataType = unknown>(
15-
props: EdgeProps<EdgeDataType>
16-
) {
17-
const nodes = useNodes<NodeDataType>()
18+
export const SmartBezierEdge: React.FC<EdgeProps<DefaultEdgeDataType>> = (
19+
props
20+
) => {
21+
return <SmartBezierEdgeInner {...props} />
22+
}
23+
24+
function SmartBezierEdgeInner<
25+
TEdgeDataType extends DefaultEdgeDataType = DefaultEdgeDataType,
26+
TNodeDataType extends DefaultNodeDataType = DefaultNodeDataType
27+
>(props: EdgeProps<TEdgeDataType>) {
28+
const nodes = useNodes<Node<TNodeDataType>>()
1829

1930
return (
20-
<SmartEdge<EdgeDataType, NodeDataType>
31+
<SmartEdge<TEdgeDataType, TNodeDataType>
2132
{...props}
2233
options={BezierConfiguration}
2334
nodes={nodes}

src/SmartEdge/SmartEdge.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Edge } from '@xyflow/react'
2+
3+
export type DefaultEdgeDataType = Edge<
4+
Record<string, unknown>,
5+
string | undefined
6+
>
7+
export type DefaultNodeDataType = Record<string, unknown>

src/SmartEdge/index.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1+
import { BezierEdge, BaseEdge } from '@xyflow/react'
12
import React from 'react'
2-
import { BezierEdge, BaseEdge } from 'reactflow'
33
import { getSmartEdge } from '../getSmartEdge'
4+
import type {
5+
DefaultEdgeDataType,
6+
DefaultNodeDataType
7+
} from './SmartEdge.types'
48
import type { GetSmartEdgeOptions } from '../getSmartEdge'
5-
import type { EdgeProps, Node } from 'reactflow'
9+
import type { EdgeProps, Node, StepEdge, StraightEdge } from '@xyflow/react'
610

7-
export type EdgeElement = typeof BezierEdge
11+
export type EdgeElement =
12+
| typeof BezierEdge
13+
| typeof StepEdge
14+
| typeof StraightEdge
815

916
export type SmartEdgeOptions = GetSmartEdgeOptions & {
1017
fallback?: EdgeElement
1118
}
1219

13-
export interface SmartEdgeProps<EdgeDataType = unknown, NodeDataType = unknown>
14-
extends EdgeProps<EdgeDataType> {
15-
nodes: Node<NodeDataType>[]
20+
export interface SmartEdgeProps<
21+
TEdgeDataType extends DefaultEdgeDataType = DefaultEdgeDataType,
22+
TNodeDataType extends DefaultNodeDataType = DefaultNodeDataType
23+
> extends EdgeProps<TEdgeDataType> {
24+
nodes: Node<TNodeDataType>[]
1625
options: SmartEdgeOptions
1726
}
1827

19-
export function SmartEdge<EdgeDataType = unknown, NodeDataType = unknown>({
28+
export function SmartEdge<
29+
TEdgeDataType extends DefaultEdgeDataType = DefaultEdgeDataType,
30+
TNodeDataType extends DefaultNodeDataType = DefaultNodeDataType
31+
>({
2032
nodes,
2133
options,
2234
...edgeProps
23-
}: SmartEdgeProps<EdgeDataType, NodeDataType>) {
35+
}: SmartEdgeProps<TEdgeDataType, TNodeDataType>) {
2436
const {
2537
sourceX,
2638
sourceY,

src/SmartStepEdge/index.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1+
import { useNodes, StepEdge } from '@xyflow/react'
12
import React from 'react'
2-
import { useNodes, StepEdge } from 'reactflow'
33
import { SmartEdge } from '../SmartEdge'
44
import {
55
svgDrawStraightLinePath,
66
pathfindingJumpPointNoDiagonal
77
} from '../functions'
88
import type { SmartEdgeOptions } from '../SmartEdge'
9-
import type { EdgeProps } from 'reactflow'
9+
import type { EdgeProps, Node } from '@xyflow/react'
10+
import type {
11+
DefaultEdgeDataType,
12+
DefaultNodeDataType
13+
} from 'SmartEdge/SmartEdge.types'
1014

1115
const StepConfiguration: SmartEdgeOptions = {
1216
drawEdge: svgDrawStraightLinePath,
1317
generatePath: pathfindingJumpPointNoDiagonal,
1418
fallback: StepEdge
1519
}
1620

17-
export function SmartStepEdge<EdgeDataType = unknown, NodeDataType = unknown>(
18-
props: EdgeProps<EdgeDataType>
19-
) {
20-
const nodes = useNodes<NodeDataType>()
21+
export const SmartStepEdge: React.FC<EdgeProps<DefaultEdgeDataType>> = (
22+
props
23+
) => {
24+
return <SmartStepEdgeInner {...props} />
25+
}
26+
27+
function SmartStepEdgeInner<
28+
EdgeDataType extends DefaultEdgeDataType = DefaultEdgeDataType,
29+
NodeDataType extends DefaultNodeDataType = DefaultNodeDataType
30+
>(props: EdgeProps<EdgeDataType>) {
31+
const nodes = useNodes<Node<NodeDataType>>()
2132

2233
return (
2334
<SmartEdge<EdgeDataType, NodeDataType>

src/SmartStraightEdge/index.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import { useNodes, StraightEdge } from '@xyflow/react'
12
import React from 'react'
2-
import { useNodes, StraightEdge } from 'reactflow'
33
import { SmartEdge } from '../SmartEdge'
44
import {
55
svgDrawStraightLinePath,
66
pathfindingAStarNoDiagonal
77
} from '../functions'
88
import type { SmartEdgeOptions } from '../SmartEdge'
9-
import type { EdgeProps } from 'reactflow'
9+
import type { EdgeProps, Node } from '@xyflow/react'
10+
import type {
11+
DefaultEdgeDataType,
12+
DefaultNodeDataType
13+
} from 'SmartEdge/SmartEdge.types'
1014

1115
const StraightConfiguration: SmartEdgeOptions = {
1216
drawEdge: svgDrawStraightLinePath,
1317
generatePath: pathfindingAStarNoDiagonal,
1418
fallback: StraightEdge
1519
}
1620

17-
export function SmartStraightEdge<
18-
EdgeDataType = unknown,
19-
NodeDataType = unknown
21+
export const SmartStraightEdge: React.FC<EdgeProps<DefaultEdgeDataType>> = (
22+
props
23+
) => {
24+
return <SmartStraightEdgeInner {...props} />
25+
}
26+
27+
function SmartStraightEdgeInner<
28+
EdgeDataType extends DefaultEdgeDataType = DefaultEdgeDataType,
29+
NodeDataType extends DefaultNodeDataType = DefaultNodeDataType
2030
>(props: EdgeProps<EdgeDataType>) {
21-
const nodes = useNodes<NodeDataType>()
31+
const nodes = useNodes<Node<NodeDataType>>()
2232

2333
return (
2434
<SmartEdge<EdgeDataType, NodeDataType>

src/functions/createGrid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { graphToGridPoint } from './pointConversion'
77
import { round, roundUp } from './utils'
88
import type { NodeBoundingBox, GraphBoundingBox } from './getBoundingBoxes'
9-
import type { Position } from 'reactflow'
9+
import type { Position } from '@xyflow/react'
1010

1111
export type PointInfo = {
1212
x: number

src/functions/drawSvgPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { XYPosition } from 'reactflow'
1+
import type { XYPosition } from '@xyflow/react'
22

33
/**
44
* Takes source and target {x, y} points, together with an array of number

0 commit comments

Comments
 (0)