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:
26
resources/js/wysiwyg/api/content.ts
Normal file
26
resources/js/wysiwyg/api/content.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user