import {LexicalEditor} from "lexical"; import { appendHtmlToEditor, focusEditor, insertHtmlIntoEditor, prependHtmlToEditor, setEditorContentFromHtml } from "../utils/actions"; type EditorEventContent = { html: string; markdown: string; }; function getContentToInsert(eventContent: EditorEventContent): string { return eventContent.html || ''; } export function listen(editor: LexicalEditor): void { window.$events.listen('editor::replace', eventContent => { const html = getContentToInsert(eventContent); setEditorContentFromHtml(editor, html); }); window.$events.listen('editor::append', eventContent => { const html = getContentToInsert(eventContent); appendHtmlToEditor(editor, html); }); window.$events.listen('editor::prepend', eventContent => { const html = getContentToInsert(eventContent); prependHtmlToEditor(editor, html); }); window.$events.listen('editor::insert', eventContent => { const html = getContentToInsert(eventContent); insertHtmlIntoEditor(editor, html); }); window.$events.listen('editor::focus', () => { focusEditor(editor); }); }