]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/index.ts
Lexical: Linked up saving logic of editor via interface
[bookstack] / resources / js / wysiwyg / index.ts
index 3ca01835f288d2625052469bed831752236197d0..09b6e060b678dc66f89da8d366e4c2b7c5a37d18 100644 (file)
@@ -1,14 +1,14 @@
-import {createEditor, CreateEditorArgs} from 'lexical';
+import {createEditor, CreateEditorArgs, LexicalEditor} from 'lexical';
 import {createEmptyHistoryState, registerHistory} from '@lexical/history';
 import {registerRichText} from '@lexical/rich-text';
 import {mergeRegister} from '@lexical/utils';
 import {getNodesForPageEditor} from './nodes';
 import {buildEditorUI} from "./ui";
-import {setEditorContentFromHtml} from "./actions";
+import {getEditorContentAsHtml, setEditorContentFromHtml} from "./actions";
 import {registerTableResizer} from "./ui/framework/helpers/table-resizer";
 import {el} from "./helpers";
 
-export function createPageEditorInstance(container: HTMLElement, htmlContent: string) {
+export function createPageEditorInstance(container: HTMLElement, htmlContent: string): SimpleWysiwygEditorInterface {
     const config: CreateEditorArgs = {
         namespace: 'BookStackPageEditor',
         nodes: getNodesForPageEditor(),
@@ -29,8 +29,12 @@ export function createPageEditorInstance(container: HTMLElement, htmlContent: st
 
     const editArea = el('div', {
         contenteditable: 'true',
+        class: 'editor-content-area page-content',
     });
-    container.append(editArea);
+    const editWrap = el('div', {
+        class: 'editor-content-wrap',
+    }, [editArea]);
+    container.append(editWrap);
     container.classList.add('editor-container');
 
     const editor = createEditor(config);
@@ -53,4 +57,18 @@ export function createPageEditorInstance(container: HTMLElement, htmlContent: st
     });
 
     buildEditorUI(container, editArea, editor);
+
+    return new SimpleWysiwygEditorInterface(editor);
 }
+
+export class SimpleWysiwygEditorInterface {
+    protected editor: LexicalEditor;
+
+    constructor(editor: LexicalEditor) {
+        this.editor = editor;
+    }
+
+    async getContentAsHtml(): Promise<string> {
+        return await getEditorContentAsHtml(this.editor);
+    }
+}
\ No newline at end of file