Skip to content

Commit

Permalink
refactor: update format
Browse files Browse the repository at this point in the history
  • Loading branch information
kurunbelemir committed Jan 13, 2025
1 parent 9148879 commit 4056e80
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 151 deletions.
5 changes: 2 additions & 3 deletions library/lib/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ function App({ onReactFlowInit }: AppProps) {
const [nodes, , onNodesChange] = useNodesState(initialNodes)
const [edges, , onEdgesChange] = useEdgesState(initialEdges)
const { onDrop, onDragOver } = useDragDrop()
const {onConnect} = useConnect()
const {onReconnect} = useReconnect()
const { onConnect } = useConnect()
const { onReconnect } = useReconnect()


return (
<div style={{ display: "flex", width: "100vw", height: "100vh" }}>
<Sidebar />
Expand Down
44 changes: 22 additions & 22 deletions library/lib/edges/AggregationEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import { BaseEdge, EdgeProps, getSmoothStepPath } from "@xyflow/react"

// Aggregation Edge (White Rhombus)
export const AggregationEdge = ({
id,
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#white-rhombus)"
style={{
stroke: "#000000",
}}
/>
)
}
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#white-rhombus)"
style={{
stroke: "#000000",
}}
/>
)
}
43 changes: 21 additions & 22 deletions library/lib/edges/BiAssociationEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ import { BaseEdge, EdgeProps, getSmoothStepPath } from "@xyflow/react"

// Uni-Directional Association Edge (Black Arrow)
export const BiAssociationEdge = ({
id,
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
})
return (
<BaseEdge
id={id}
path={edgePath}
style={{
stroke: "#000000",
}}
/>
)
}

})
return (
<BaseEdge
id={id}
path={edgePath}
style={{
stroke: "#000000",
}}
/>
)
}
44 changes: 22 additions & 22 deletions library/lib/edges/CompositionEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import { BaseEdge, EdgeProps, getSmoothStepPath } from "@xyflow/react"

// Composition Edge (Black Rhombus)
export const CompositionEdge = ({
id,
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#black-rhombus)"
style={{
stroke: "#000000",
}}
/>
)
}
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#black-rhombus)"
style={{
stroke: "#000000",
}}
/>
)
}
48 changes: 24 additions & 24 deletions library/lib/edges/DependencyEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ import { BaseEdge, EdgeProps, getSmoothStepPath } from "@xyflow/react"

// Dependency Edge (Dotted White Arrow)
export const DependencyEdge = ({
id,
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#custom-arrow)"
strokeDasharray="8"
strokeWidth={4}
style={{
stroke: "#000000",
}}
/>
)
}
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#custom-arrow)"
strokeDasharray="8"
strokeWidth={4}
style={{
stroke: "#000000",
}}
/>
)
}
2 changes: 1 addition & 1 deletion library/lib/edges/InheritanceEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export const InheritanceEdge = ({
}}
/>
)
}
}
48 changes: 24 additions & 24 deletions library/lib/edges/RealizationEdge.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { BaseEdge, EdgeProps, getSmoothStepPath } from "@xyflow/react"
// Realization Edge (Dotted White Triangle)
export const RealizationEdge = ({
id,
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
sourcePosition,
targetPosition,
}: EdgeProps) => {
const [edgePath] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#white-triangle)"
strokeDasharray="8"
strokeWidth={4}
style={{
stroke: "#000000",
}}
/>
)
}
})
return (
<BaseEdge
id={id}
path={edgePath}
markerEnd="url(#white-triangle)"
strokeDasharray="8"
strokeWidth={4}
style={{
stroke: "#000000",
}}
/>
)
}
2 changes: 1 addition & 1 deletion library/lib/edges/UniAssociationEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export const UniAssociationEdge = ({
}}
/>
)
}
}
1 change: 0 additions & 1 deletion library/lib/edges/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export * from "./types"
export * from "./AggregationEdge"
export * from "./BiAssociationEdge"
Expand Down
35 changes: 14 additions & 21 deletions library/lib/hooks/useConnect.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import {
addEdge,
Edge,
Connection,
useReactFlow
} from "@xyflow/react"
import { useCallback} from "react"
import { addEdge, Edge, Connection, useReactFlow } from "@xyflow/react"
import { useCallback } from "react"

export const useConnect = () => {

const { setEdges} = useReactFlow()
const { setEdges } = useReactFlow()
const onConnect = useCallback(
(connection: Connection) => {
const edge: Edge = {
...connection,
id: `${Date.now()}-${connection.source}-${connection.target}`,
type: "biassociation",
selected: true,
}
setEdges((edges) => addEdge(edge, edges))
},
[setEdges]
)
(connection: Connection) => {
const edge: Edge = {
...connection,
id: `${Date.now()}-${connection.source}-${connection.target}`,
type: "biassociation",
selected: true,
}
setEdges((edges) => addEdge(edge, edges))
},
[setEdges]
)
return { onConnect }
}

13 changes: 3 additions & 10 deletions library/lib/hooks/useReconnect.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import {
reconnectEdge,
Edge,
Connection,
useReactFlow
} from "@xyflow/react"
import { useCallback} from "react"
import { reconnectEdge, Edge, Connection, useReactFlow } from "@xyflow/react"
import { useCallback } from "react"

export const useReconnect = () => {

const { setEdges} = useReactFlow()
const { setEdges } = useReactFlow()
const onReconnect = useCallback(
(oldEdge: Edge, newConnection: Connection) =>
setEdges((els) =>
Expand All @@ -23,4 +17,3 @@ export const useReconnect = () => {
)
return { onReconnect }
}

0 comments on commit 4056e80

Please sign in to comment.