-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
web/app/components/base/prompt-editor/plugins/update-block.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' | ||
import { textToEditorState } from '../utils' | ||
import { useEventEmitterContextContext } from '@/context/event-emitter' | ||
|
||
export const PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER = 'PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER' | ||
|
||
const UpdateBlock = () => { | ||
const { eventEmitter } = useEventEmitterContextContext() | ||
const [editor] = useLexicalComposerContext() | ||
|
||
eventEmitter?.useSubscription((v: any) => { | ||
if (v.type === PROMPT_EDITOR_UPDATE_VALUE_BY_EVENT_EMITTER) { | ||
const editorState = editor.parseEditorState(textToEditorState(v.payload)) | ||
editor.setEditorState(editorState) | ||
} | ||
}) | ||
|
||
return null | ||
} | ||
|
||
export default UpdateBlock |