From d0509213d14b9314ad268aac806b185693ffd624 Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Mon, 1 Apr 2024 16:46:21 +0800 Subject: [PATCH] prompt editor --- web/app/components/base/prompt-editor/index.tsx | 4 +++- .../base/prompt-editor/plugins/update-block.tsx | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/app/components/base/prompt-editor/index.tsx b/web/app/components/base/prompt-editor/index.tsx index 774ee6a489..43b19de921 100644 --- a/web/app/components/base/prompt-editor/index.tsx +++ b/web/app/components/base/prompt-editor/index.tsx @@ -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 = ({ + instanceId, className, placeholder, placeholderClassName, @@ -204,7 +206,7 @@ const PromptEditor: FC = ({ } - + {/* */} diff --git a/web/app/components/base/prompt-editor/plugins/update-block.tsx b/web/app/components/base/prompt-editor/plugins/update-block.tsx index df84aa02e6..b629537ed9 100644 --- a/web/app/components/base/prompt-editor/plugins/update-block.tsx +++ b/web/app/components/base/prompt-editor/plugins/update-block.tsx @@ -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) }