Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
15f13209
Commit
15f13209
authored
Feb 21, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node handle
parent
dbf3b7ad
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
13 deletions
+69
-13
page.tsx
web/app/(commonLayout)/workflow/page.tsx
+34
-2
custom-edge.tsx
web/app/components/workflow/custom-edge.tsx
+1
-1
hooks.ts
web/app/components/workflow/hooks.ts
+2
-5
index.tsx
web/app/components/workflow/index.tsx
+1
-0
node.tsx
web/app/components/workflow/nodes/_base/node.tsx
+1
-1
index.tsx
web/app/components/workflow/nodes/index.tsx
+13
-4
style.css
web/app/components/workflow/style.css
+3
-0
zoom-in-out.tsx
web/app/components/workflow/zoom-in-out.tsx
+14
-0
No files found.
web/app/(commonLayout)/workflow/page.tsx
View file @
15f13209
...
@@ -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
:
1
30
},
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
=
()
=>
{
...
...
web/app/components/workflow/custom-edge.tsx
View file @
15f13209
...
@@ -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=
{
`
...
...
web/app/components/workflow/hooks.ts
View file @
15f13209
...
@@ -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
],
}
}
...
...
web/app/components/workflow/index.tsx
View file @
15f13209
...
@@ -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
,
...
...
web/app/components/workflow/nodes/_base/node.tsx
View file @
15f13209
...
@@ -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-[2
96
px] bg-[#fcfdff] rounded-2xl shadow-xs
group relative pb-2 w-[2
40
px] 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'}
`
}
`
}
...
...
web/app/components/workflow/nodes/index.tsx
View file @
15f13209
...
@@ -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
`
}
/>
/>
</>
</>
)
)
...
...
web/app/components/workflow/style.css
0 → 100644
View file @
15f13209
.react-flow__edge-path
{
stroke-width
:
2px
!important
;
}
\ No newline at end of file
web/app/components/workflow/zoom-in-out.tsx
View file @
15f13209
...
@@ -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
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment