prompt editor

This commit is contained in:
StyleZhang 2024-04-01 16:46:21 +08:00
parent 5b81234db8
commit d0509213d1
2 changed files with 10 additions and 3 deletions

View File

@ -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>

View File

@ -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)
}