]> BookStack Code Mirror - bookstack/blob - resources/js/markdown/editor.js
Refactored markdown editor logic
[bookstack] / resources / js / markdown / editor.js
1 import {Markdown} from "./markdown";
2 import {Display} from "./display";
3 import {Actions} from "./actions";
4 import {listen} from "./common-events";
5 import {init as initCodemirror} from "./codemirror";
6
7
8 /**
9  * Initiate a new markdown editor instance.
10  * @param {MarkdownEditorConfig} config
11  * @returns {Promise<MarkdownEditor>}
12  */
13 export async function init(config) {
14
15     /**
16      * @type {MarkdownEditor}
17      */
18     const editor = {
19         config,
20         markdown: new Markdown(),
21     };
22
23     editor.actions = new Actions(editor);
24     editor.display = new Display(editor);
25     editor.cm = await initCodemirror(editor);
26
27     listen(editor);
28
29     return editor;
30 }
31
32
33 /**
34  * @typedef MarkdownEditorConfig
35  * @property {String} pageId
36  * @property {Element} container
37  * @property {Element} displayEl
38  * @property {HTMLTextAreaElement} inputEl
39  * @property {String} drawioUrl
40  * @property {Object<String, String>} text
41  */
42
43 /**
44  * @typedef MarkdownEditor
45  * @property {MarkdownEditorConfig} config
46  * @property {Display} display
47  * @property {Markdown} markdown
48  * @property {Actions} actions
49  * @property {CodeMirror} cm
50  */