Commit 15f13209 authored by StyleZhang's avatar StyleZhang

node handle

parent dbf3b7ad
...@@ -8,13 +8,45 @@ const initialNodes = [ ...@@ -8,13 +8,45 @@ const initialNodes = [
{ {
id: '1', id: '1',
type: 'custom', type: 'custom',
position: { x: 330, y: 30 }, position: { x: 130, y: 130 },
data: { type: 'start' }, data: { type: 'start' },
}, },
{
id: '2',
type: 'custom',
position: { x: 434, y: 130 },
data: { type: 'code' },
},
{
id: '3',
type: 'custom',
position: { x: 738, y: 130 },
data: { type: 'llm' },
},
{
id: '4',
type: 'custom',
position: { x: 738, y: 330 },
data: { type: 'llm' },
},
] ]
const initialEdges = [ const initialEdges = [
{
id: '0',
source: '1',
target: '2',
},
{
id: '1',
source: '2',
target: '3',
},
{
id: '2',
source: '2',
target: '4',
},
] ]
const Page: FC = () => { const Page: FC = () => {
......
...@@ -28,7 +28,7 @@ const CustomEdge = ({ ...@@ -28,7 +28,7 @@ const CustomEdge = ({
return ( return (
<> <>
<BaseEdge id={id} path={edgePath} /> <BaseEdge id={id} path={edgePath} style={{ strokeWidth: 5 }} />
<EdgeLabelRenderer> <EdgeLabelRenderer>
<div <div
className={` className={`
......
...@@ -31,15 +31,12 @@ export const useWorkflow = ( ...@@ -31,15 +31,12 @@ export const useWorkflow = (
}, [nodes, selectedNodeId]) }, [nodes, selectedNodeId])
const handleAddNextNode = useCallback((prevNode: Node, nextNodeType: BlockEnum) => { const handleAddNextNode = useCallback((prevNode: Node, nextNodeType: BlockEnum) => {
const prevNodeDom = document.querySelector(`.react-flow__node-custom[data-id="${prevNode.id}"]`)
const prevNodeDomHeight = prevNodeDom?.getBoundingClientRect().height || 0
const nextNode = { const nextNode = {
id: `node-${Date.now()}`, id: `node-${Date.now()}`,
type: 'custom', type: 'custom',
position: { position: {
x: prevNode.position.x, x: prevNode.position.x + 304,
y: prevNode.position.y + prevNodeDomHeight + 64, y: prevNode.position.y,
}, },
data: NodeInitialData[nextNodeType], data: NodeInitialData[nextNodeType],
} }
......
...@@ -8,6 +8,7 @@ import ReactFlow, { ...@@ -8,6 +8,7 @@ import ReactFlow, {
useReactFlow, useReactFlow,
} from 'reactflow' } from 'reactflow'
import 'reactflow/dist/style.css' import 'reactflow/dist/style.css'
import './style.css'
import { import {
WorkflowContext, WorkflowContext,
useWorkflowContext, useWorkflowContext,
......
...@@ -59,7 +59,7 @@ const BaseNode: FC<BaseNodeProps> = ({ ...@@ -59,7 +59,7 @@ const BaseNode: FC<BaseNodeProps> = ({
return ( return (
<div <div
className={` className={`
group relative pb-2 w-[296px] bg-[#fcfdff] rounded-2xl shadow-xs group relative pb-2 w-[240px] bg-[#fcfdff] rounded-2xl shadow-xs
hover:shadow-lg hover:shadow-lg
${selectedNodeId === nodeId ? 'border-[2px] border-primary-600' : 'border border-white'} ${selectedNodeId === nodeId ? 'border-[2px] border-primary-600' : 'border border-white'}
`} `}
......
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
Position, Position,
} from 'reactflow' } from 'reactflow'
import { useWorkflowContext } from '../context' import { useWorkflowContext } from '../context'
import { BlockEnum } from '../types'
import { import {
NodeComponentMap, NodeComponentMap,
PanelComponentMap, PanelComponentMap,
...@@ -22,8 +23,13 @@ const CustomNode = ({ ...@@ -22,8 +23,13 @@ const CustomNode = ({
<> <>
<Handle <Handle
type='target' type='target'
position={Position.Top} position={Position.Left}
className='!-top-0.5 !w-2 !h-0.5 !bg-primary-500 !rounded-none !border-none !min-h-[2px]' className={`
!top-4 !left-0 !w-4 !h-4 !bg-transparent !rounded-none !outline-none !border-none !translate-y-0 z-[1]
after:absolute after:w-0.5 after:h-2 after:-left-0.5 after:top-1 after:bg-primary-500
${data.type === BlockEnum.Start && 'opacity-0'}
`}
isConnectable={data.type !== BlockEnum.Start}
/> />
<BaseNode <BaseNode
id={id} id={id}
...@@ -33,8 +39,11 @@ const CustomNode = ({ ...@@ -33,8 +39,11 @@ const CustomNode = ({
</BaseNode> </BaseNode>
<Handle <Handle
type='source' type='source'
position={Position.Bottom} position={Position.Right}
className='!-bottom-0.5 !w-2 !h-0.5 !bg-primary-500 !rounded-none !border-none !min-h-[2px]' className={`
!top-4 !right-0 !w-4 !h-4 !bg-transparent !rounded-none !outline-none !border-none !translate-y-0
after:absolute after:w-0.5 after:h-2 after:-right-0.5 after:top-1 after:bg-primary-500
`}
/> />
</> </>
) )
......
.react-flow__edge-path {
stroke-width: 2px !important;
}
\ No newline at end of file
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
memo, memo,
useState, useState,
} from 'react' } from 'react'
import { useWorkflowContext } from './context'
import { import {
PortalToFollowElem, PortalToFollowElem,
PortalToFollowElemContent, PortalToFollowElemContent,
...@@ -42,8 +43,20 @@ const ZOOM_IN_OUT_OPTIONS = [ ...@@ -42,8 +43,20 @@ const ZOOM_IN_OUT_OPTIONS = [
] ]
const ZoomInOut: FC = () => { const ZoomInOut: FC = () => {
const { reactFlow } = useWorkflowContext()
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const handleZoom = (type: string) => {
if (type === 'in')
reactFlow.zoomIn()
if (type === 'out')
reactFlow.zoomOut()
if (type === 'fit')
reactFlow.fitView()
}
return ( return (
<PortalToFollowElem <PortalToFollowElem
placement='top-start' placement='top-start'
...@@ -78,6 +91,7 @@ const ZoomInOut: FC = () => { ...@@ -78,6 +91,7 @@ const ZoomInOut: FC = () => {
<div <div
key={option.key} key={option.key}
className='flex items-center px-3 h-8 rounded-lg hover:bg-gray-50 cursor-pointer text-sm text-gray-700' className='flex items-center px-3 h-8 rounded-lg hover:bg-gray-50 cursor-pointer text-sm text-gray-700'
onClick={() => handleZoom(option.key)}
> >
{option.text} {option.text}
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment