mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-10 13:43:38 +08:00
Refactored markdown editor logic
Split out the markdown editor logic into seperate components to provide a more orgranised heirachy with feature-specific files.
This commit is contained in:
50
resources/js/markdown/editor.js
Normal file
50
resources/js/markdown/editor.js
Normal file
@ -0,0 +1,50 @@
|
||||
import {Markdown} from "./markdown";
|
||||
import {Display} from "./display";
|
||||
import {Actions} from "./actions";
|
||||
import {listen} from "./common-events";
|
||||
import {init as initCodemirror} from "./codemirror";
|
||||
|
||||
|
||||
/**
|
||||
* Initiate a new markdown editor instance.
|
||||
* @param {MarkdownEditorConfig} config
|
||||
* @returns {Promise<MarkdownEditor>}
|
||||
*/
|
||||
export async function init(config) {
|
||||
|
||||
/**
|
||||
* @type {MarkdownEditor}
|
||||
*/
|
||||
const editor = {
|
||||
config,
|
||||
markdown: new Markdown(),
|
||||
};
|
||||
|
||||
editor.actions = new Actions(editor);
|
||||
editor.display = new Display(editor);
|
||||
editor.cm = await initCodemirror(editor);
|
||||
|
||||
listen(editor);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @typedef MarkdownEditorConfig
|
||||
* @property {String} pageId
|
||||
* @property {Element} container
|
||||
* @property {Element} displayEl
|
||||
* @property {HTMLTextAreaElement} inputEl
|
||||
* @property {String} drawioUrl
|
||||
* @property {Object<String, String>} text
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef MarkdownEditor
|
||||
* @property {MarkdownEditorConfig} config
|
||||
* @property {Display} display
|
||||
* @property {Markdown} markdown
|
||||
* @property {Actions} actions
|
||||
* @property {CodeMirror} cm
|
||||
*/
|
Reference in New Issue
Block a user