1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Lexical: Linked up saving logic of editor via interface

This commit is contained in:
Dan Brown
2024-07-04 13:09:53 +01:00
parent a8f1160743
commit 04c7e680fd
5 changed files with 52 additions and 15 deletions

View 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(),
@ -57,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);
}
}