]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/services/common-events.ts
respective book and chapter structure added.
[bookstack] / resources / js / wysiwyg / services / common-events.ts
1 import {LexicalEditor} from "lexical";
2 import {
3     appendHtmlToEditor,
4     focusEditor,
5     insertHtmlIntoEditor,
6     prependHtmlToEditor,
7     setEditorContentFromHtml
8 } from "../utils/actions";
9
10 type EditorEventContent = {
11     html: string;
12     markdown: string;
13 };
14
15 function getContentToInsert(eventContent: EditorEventContent): string {
16     return eventContent.html || '';
17 }
18
19 export function listen(editor: LexicalEditor): void {
20     window.$events.listen<EditorEventContent>('editor::replace', eventContent => {
21         const html = getContentToInsert(eventContent);
22         setEditorContentFromHtml(editor, html);
23     });
24
25     window.$events.listen<EditorEventContent>('editor::append', eventContent => {
26         const html = getContentToInsert(eventContent);
27         appendHtmlToEditor(editor, html);
28     });
29
30     window.$events.listen<EditorEventContent>('editor::prepend', eventContent => {
31         const html = getContentToInsert(eventContent);
32         prependHtmlToEditor(editor, html);
33     });
34
35     window.$events.listen<EditorEventContent>('editor::insert', eventContent => {
36         const html = getContentToInsert(eventContent);
37         insertHtmlIntoEditor(editor, html);
38     });
39
40     window.$events.listen<EditorEventContent>('editor::focus', () => {
41         focusEditor(editor);
42     });
43 }