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
71d3f71e
Commit
71d3f71e
authored
Feb 21, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: code editor base
parent
13a54c3f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
3 deletions
+134
-3
base.tsx
...omponents/workflow/nodes/_base/components/editor/base.tsx
+71
-0
code-editor.tsx
...ts/workflow/nodes/_base/components/editor/code-editor.tsx
+39
-0
panel.tsx
web/app/components/workflow/nodes/code/panel.tsx
+12
-1
use-config.ts
web/app/components/workflow/nodes/code/use-config.ts
+12
-2
No files found.
web/app/components/workflow/nodes/_base/components/editor/base.tsx
0 → 100644
View file @
71d3f71e
'use client'
import
type
{
FC
}
from
'react'
import
React
,
{
useCallback
,
useState
}
from
'react'
import
copy
from
'copy-to-clipboard'
import
cn
from
'classnames'
import
PromptEditorHeightResizeWrap
from
'@/app/components/app/configuration/config-prompt/prompt-editor-height-resize-wrap'
import
{
Clipboard
,
ClipboardCheck
}
from
'@/app/components/base/icons/src/vender/line/files'
import
{
Expand04
}
from
'@/app/components/base/icons/src/vender/solid/arrows'
type
Props
=
{
className
?:
string
title
:
JSX
.
Element
headerRight
?:
JSX
.
Element
children
:
JSX
.
Element
minHeight
?:
number
value
:
string
isFocus
:
boolean
}
const
Base
:
FC
<
Props
>
=
({
className
,
title
,
headerRight
,
children
,
minHeight
=
120
,
value
,
isFocus
,
})
=>
{
const
editorContentMinHeight
=
minHeight
-
28
const
[
editorContentHeight
,
setEditorContentHeight
]
=
useState
(
editorContentMinHeight
)
const
[
isCopied
,
setIsCopied
]
=
React
.
useState
(
false
)
const
handleCopy
=
useCallback
(()
=>
{
copy
(
value
)
setIsCopied
(
true
)
},
[
value
])
const
[
isExpanded
,
setIsExpanded
]
=
React
.
useState
(
false
)
const
toggleExpand
=
useCallback
(()
=>
{
setIsExpanded
(
!
isExpanded
)
},
[
isExpanded
])
return
(
<
div
className=
{
cn
(
className
,
'rounded-lg border'
,
isFocus
?
'bg-white border-gray-200'
:
'bg-gray-100 border-gray-100'
)
}
>
<
div
className=
'flex justify-between items-center h-7 pt-1 pl-3 pr-1'
>
<
div
className=
''
>
{
title
}
</
div
>
<
div
className=
'flex'
>
{
headerRight
}
{
!
isCopied
?
(
<
Clipboard
className=
'mx-1 w-3.5 h-3.5 text-gray-500 cursor-pointer'
onClick=
{
handleCopy
}
/>
)
:
(
<
ClipboardCheck
className=
'mx-1 w-3.5 h-3.5 text-gray-500'
/>
)
}
<
Expand04
className=
'ml-2 mr-2 w-3.5 h-3.5 text-gray-500 cursor-pointer'
onClick=
{
toggleExpand
}
/>
</
div
>
</
div
>
<
PromptEditorHeightResizeWrap
height=
{
editorContentHeight
}
minHeight=
{
editorContentMinHeight
}
onHeightChange=
{
setEditorContentHeight
}
>
<
div
className=
'h-full'
>
{
children
}
</
div
>
</
PromptEditorHeightResizeWrap
>
</
div
>
)
}
export
default
React
.
memo
(
Base
)
web/app/components/workflow/nodes/_base/components/editor/code-editor.tsx
0 → 100644
View file @
71d3f71e
'use client'
import
type
{
FC
}
from
'react'
import
React
from
'react'
import
type
{
CodeLanguage
}
from
'../../../code/types'
import
Base
from
'./base'
type
Props
=
{
value
:
string
onChange
:
(
value
:
string
)
=>
void
codeLanguage
:
string
onCodeLanguageChange
:
(
codeLanguage
:
CodeLanguage
)
=>
void
}
const
CodeEditor
:
FC
<
Props
>
=
({
value
,
onChange
,
})
=>
{
const
[
isFocus
,
setIsFocus
]
=
React
.
useState
(
false
)
return
(
<
div
>
<
Base
title=
{
<
div
>
Code
</
div
>
}
value=
{
value
}
isFocus=
{
isFocus
}
minHeight=
{
86
}
>
<
textarea
value=
{
value
}
onChange=
{
e
=>
onChange
(
e
.
target
.
value
)
}
onFocus=
{
()
=>
setIsFocus
(
true
)
}
onBlur=
{
()
=>
setIsFocus
(
false
)
}
className=
'w-full h-full p-3 resize-none bg-transparent'
/>
</
Base
>
</
div
>
)
}
export
default
React
.
memo
(
CodeEditor
)
web/app/components/workflow/nodes/code/panel.tsx
View file @
71d3f71e
...
...
@@ -5,7 +5,8 @@ import { mockData } from './mock'
import
VarList
from
'@/app/components/workflow/nodes/_base/components/variable/var-list'
import
AddButton
from
'@/app/components/base/button/add-button'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
CodeEditor
from
'@/app/components/workflow/nodes/_base/components/editor/code-editor'
const
i18nPrefix
=
'workflow.nodes.code'
const
Panel
:
FC
=
()
=>
{
...
...
@@ -16,6 +17,8 @@ const Panel: FC = () => {
inputs
,
handleVarListChange
,
handleAddVariable
,
handleCodeChange
,
handleCodeLanguageChange
,
}
=
useConfig
(
mockData
)
return
(
<
div
className=
'mt-2 px-4 space-y-4'
>
...
...
@@ -31,6 +34,14 @@ const Panel: FC = () => {
onChange=
{
handleVarListChange
}
/>
</
Field
>
<
Split
/>
<
CodeEditor
value=
{
inputs
.
code
}
onChange=
{
handleCodeChange
}
codeLanguage=
{
inputs
.
code_language
}
onCodeLanguageChange=
{
handleCodeLanguageChange
}
/>
<
Split
/>
</
div
>
)
}
...
...
web/app/components/workflow/nodes/code/use-config.ts
View file @
71d3f71e
import
{
useState
}
from
'react'
import
{
use
Callback
,
use
State
}
from
'react'
import
useVarList
from
'../_base/hooks/use-var-list'
import
type
{
CodeNodeType
}
from
'./types'
import
type
{
Code
Language
,
Code
NodeType
}
from
'./types'
const
useConfig
=
(
initInputs
:
CodeNodeType
)
=>
{
const
[
inputs
,
setInputs
]
=
useState
<
CodeNodeType
>
(
initInputs
)
...
...
@@ -9,10 +9,20 @@ const useConfig = (initInputs: CodeNodeType) => {
setInputs
,
})
const
handleCodeChange
=
useCallback
((
code
:
string
)
=>
{
setInputs
(
prev
=>
({
...
prev
,
code
}))
},
[
setInputs
])
const
handleCodeLanguageChange
=
useCallback
((
codeLanguage
:
CodeLanguage
)
=>
{
setInputs
(
prev
=>
({
...
prev
,
code_language
:
codeLanguage
}))
},
[
setInputs
])
return
{
inputs
,
handleVarListChange
,
handleAddVariable
,
handleCodeChange
,
handleCodeLanguageChange
,
}
}
...
...
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