1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-14 19:42:14 +03:00

Lexical API: Added content module, testing and documented

This commit is contained in:
Dan Brown
2025-12-05 12:15:18 +00:00
parent ebceba0afe
commit dfdcfcfdb8
9 changed files with 202 additions and 25 deletions

View File

@@ -0,0 +1,26 @@
import {EditorUiContext} from "../ui/framework/core";
import {appendHtmlToEditor, insertHtmlIntoEditor, prependHtmlToEditor} from "../utils/actions";
export class EditorApiContentModule {
readonly #context: EditorUiContext;
constructor(context: EditorUiContext) {
this.#context = context;
}
insertHtml(html: string, position: string = 'selection'): void {
const validPositions = ['start', 'end', 'selection'];
if (!validPositions.includes(position)) {
throw new Error(`Invalid position: ${position}. Valid positions are: ${validPositions.join(', ')}`);
}
if (position === 'start') {
prependHtmlToEditor(this.#context.editor, html);
} else if (position === 'end') {
appendHtmlToEditor(this.#context.editor, html);
} else {
insertHtmlIntoEditor(this.#context.editor, html);
}
}
}