mirror of https://github.com/langgenius/dify.git
prompt editor
This commit is contained in:
parent
5b81234db8
commit
d0509213d1
|
|
@ -60,6 +60,7 @@ import {
|
|||
import { useEventEmitterContextContext } from '@/context/event-emitter'
|
||||
|
||||
export type PromptEditorProps = {
|
||||
instanceId?: string
|
||||
className?: string
|
||||
placeholder?: string
|
||||
placeholderClassName?: string
|
||||
|
|
@ -78,6 +79,7 @@ export type PromptEditorProps = {
|
|||
}
|
||||
|
||||
const PromptEditor: FC<PromptEditorProps> = ({
|
||||
instanceId,
|
||||
className,
|
||||
placeholder,
|
||||
placeholderClassName,
|
||||
|
|
@ -204,7 +206,7 @@ const PromptEditor: FC<PromptEditorProps> = ({
|
|||
}
|
||||
<OnChangePlugin onChange={handleEditorChange} />
|
||||
<OnBlurBlock onBlur={onBlur} onFocus={onFocus} />
|
||||
<UpdateBlock />
|
||||
<UpdateBlock instanceId={instanceId} />
|
||||
{/* <TreeView /> */}
|
||||
</div>
|
||||
</LexicalComposer>
|
||||
|
|
|
|||
|
|
@ -4,12 +4,17 @@ import { useEventEmitterContextContext } from '@/context/event-emitter'
|
|||
|
||||
export const PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER = 'PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER'
|
||||
|
||||
const UpdateBlock = () => {
|
||||
type UpdateBlockProps = {
|
||||
instanceId?: string
|
||||
}
|
||||
const UpdateBlock = ({
|
||||
instanceId,
|
||||
}: UpdateBlockProps) => {
|
||||
const { eventEmitter } = useEventEmitterContextContext()
|
||||
const [editor] = useLexicalComposerContext()
|
||||
|
||||
eventEmitter?.useSubscription((v: any) => {
|
||||
if (v.type === PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER) {
|
||||
if (v.type === PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER && v.instanceId === instanceId) {
|
||||
const editorState = editor.parseEditorState(textToEditorState(v.payload))
|
||||
editor.setEditorState(editorState)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue