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
cc4ca942
Commit
cc4ca942
authored
Mar 06, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: prompt editor blur and focus ui
parent
3202f12c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
15 deletions
+38
-15
index.tsx
web/app/components/base/prompt-editor/index.tsx
+12
-10
on-blur-or-focus-block.tsx
...nts/base/prompt-editor/plugins/on-blur-or-focus-block.tsx
+12
-0
editor.tsx
...ponents/workflow/nodes/_base/components/prompt/editor.tsx
+14
-5
No files found.
web/app/components/base/prompt-editor/index.tsx
View file @
cc4ca942
...
...
@@ -31,7 +31,7 @@ import VariableBlock from './plugins/variable-block'
import
VariableValueBlock
from
'./plugins/variable-value-block'
import
{
VariableValueBlockNode
}
from
'./plugins/variable-value-block/node'
import
{
CustomTextNode
}
from
'./plugins/custom-text/node'
import
OnBlurBlock
from
'./plugins/on-blur-block'
import
OnBlurBlock
from
'./plugins/on-blur-
or-focus-
block'
import
{
textToEditorState
}
from
'./utils'
import
type
{
Dataset
}
from
'./plugins/context-block'
import
type
{
RoleName
}
from
'./plugins/history-block'
...
...
@@ -48,6 +48,7 @@ export type PromptEditorProps = {
editable
?:
boolean
onChange
?:
(
text
:
string
)
=>
void
onBlur
?:
()
=>
void
onFocus
?:
()
=>
void
contextBlock
?:
{
show
?:
boolean
selectable
?:
boolean
...
...
@@ -84,13 +85,14 @@ const PromptEditor: FC<PromptEditorProps> = ({
editable
=
true
,
onChange
,
onBlur
,
onFocus
,
contextBlock
=
{
show
:
true
,
selectable
:
true
,
datasets
:
[],
onAddContext
:
()
=>
{},
onInsert
:
()
=>
{},
onDelete
:
()
=>
{},
onAddContext
:
()
=>
{
},
onInsert
:
()
=>
{
},
onDelete
:
()
=>
{
},
},
historyBlock
=
{
show
:
true
,
...
...
@@ -99,9 +101,9 @@ const PromptEditor: FC<PromptEditorProps> = ({
user
:
''
,
assistant
:
''
,
},
onEditRole
:
()
=>
{},
onInsert
:
()
=>
{},
onDelete
:
()
=>
{},
onEditRole
:
()
=>
{
},
onInsert
:
()
=>
{
},
onDelete
:
()
=>
{
},
},
variableBlock
=
{
variables
:
[],
...
...
@@ -109,8 +111,8 @@ const PromptEditor: FC<PromptEditorProps> = ({
queryBlock
=
{
show
:
true
,
selectable
:
true
,
onInsert
:
()
=>
{},
onDelete
:
()
=>
{},
onInsert
:
()
=>
{
},
onDelete
:
()
=>
{
},
},
})
=>
{
const
{
eventEmitter
}
=
useEventEmitterContextContext
()
...
...
@@ -221,7 +223,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
}
<
VariableValueBlock
/>
<
OnChangePlugin
onChange=
{
handleEditorChange
}
/>
<
OnBlurBlock
onBlur=
{
onBlur
}
/>
<
OnBlurBlock
onBlur=
{
onBlur
}
onFocus=
{
onFocus
}
/>
{
/* <TreeView /> */
}
</
div
>
</
LexicalComposer
>
...
...
web/app/components/base/prompt-editor/plugins/on-blur-block.tsx
→
web/app/components/base/prompt-editor/plugins/on-blur-
or-focus-
block.tsx
View file @
cc4ca942
...
...
@@ -3,15 +3,18 @@ import { useEffect } from 'react'
import
{
BLUR_COMMAND
,
COMMAND_PRIORITY_EDITOR
,
FOCUS_COMMAND
,
}
from
'lexical'
import
{
mergeRegister
}
from
'@lexical/utils'
import
{
useLexicalComposerContext
}
from
'@lexical/react/LexicalComposerContext'
type
OnBlurBlockProps
=
{
onBlur
?:
()
=>
void
onFocus
?:
()
=>
void
}
const
OnBlurBlock
:
FC
<
OnBlurBlockProps
>
=
({
onBlur
,
onFocus
,
})
=>
{
const
[
editor
]
=
useLexicalComposerContext
()
...
...
@@ -27,6 +30,15 @@ const OnBlurBlock: FC<OnBlurBlockProps> = ({
},
COMMAND_PRIORITY_EDITOR
,
),
editor
.
registerCommand
(
FOCUS_COMMAND
,
()
=>
{
if
(
onFocus
)
onFocus
()
return
true
},
COMMAND_PRIORITY_EDITOR
,
),
)
},
[
editor
,
onBlur
])
...
...
web/app/components/workflow/nodes/_base/components/prompt/editor.tsx
View file @
cc4ca942
...
...
@@ -4,6 +4,7 @@ import React, { useCallback } from 'react'
import
cn
from
'classnames'
import
copy
from
'copy-to-clipboard'
import
{
useTranslation
}
from
'react-i18next'
import
{
useBoolean
}
from
'ahooks'
import
PromptEditorHeightResizeWrap
from
'@/app/components/app/configuration/config-prompt/prompt-editor-height-resize-wrap'
import
PromptEditor
from
'@/app/components/base/prompt-editor'
import
{
Clipboard
,
ClipboardCheck
}
from
'@/app/components/base/icons/src/vender/line/files'
...
...
@@ -44,9 +45,14 @@ const Editor: FC<Props> = ({
setIsExpanded
(
!
isExpanded
)
},
[
isExpanded
])
const
[
isFocus
,
{
setTrue
:
setFocus
,
setFalse
:
setBlur
,
}]
=
useBoolean
(
false
)
return
(
<
div
className=
{
cn
(
s
.
gradientBorder
,
'!rounded-[9px] shadow-md'
)
}
>
<
div
className=
'rounded-lg bg-white'
>
<
div
className=
{
cn
(
isFocus
&&
s
.
gradientBorder
,
'!rounded-[9px] shadow-md'
)
}
>
<
div
className=
{
cn
(
isFocus
?
'bg-white'
:
'bg-gray-100'
,
'rounded-lg'
)
}
>
<
div
className=
'pt-1 pl-3 pr-2 flex justify-between h-6 items-center'
>
<
div
className=
'leading-4 text-xs font-semibold text-gray-700 uppercase'
>
{
title
}
</
div
>
<
div
className=
'flex items-center'
>
...
...
@@ -76,8 +82,10 @@ const Editor: FC<Props> = ({
minHeight=
{
minHeight
}
onHeightChange=
{
setEditorHeight
}
footer=
{
(
<
div
className=
'pl-4 pb-2 flex'
>
<
div
className=
"h-[18px] leading-[18px] px-1 rounded-md bg-gray-100 text-xs text-gray-500"
>
{
'{x} '
}{
t
(
'workflow.nodes.common.insertVarTip'
)
}
</
div
>
<
div
className=
'pl-3 pb-2 flex'
>
{
isFocus
?
<
div
className=
"h-[18px] leading-[18px] px-1 rounded-md bg-gray-100 text-xs text-gray-500"
>
{
'{x} '
}{
t
(
'workflow.nodes.common.insertVarTip'
)
}
</
div
>
:
<
div
className=
'h-[18px]'
></
div
>
}
</
div
>
)
}
>
...
...
@@ -112,7 +120,8 @@ const Editor: FC<Props> = ({
selectable
:
true
,
}
}
onChange=
{
onChange
}
onBlur=
{
()
=>
{
}
}
onBlur=
{
setBlur
}
onFocus=
{
setFocus
}
editable=
{
!
readOnly
}
/>
</
PromptEditorHeightResizeWrap
>
...
...
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