]> BookStack Code Mirror - bookstack/blob - resources/js/markdown/editor.js
46c35c850ac77b5e19277c00df784f6a415546c4
[bookstack] / resources / js / markdown / editor.js
1 import {Markdown} from './markdown';
2 import {Display} from './display';
3 import {Actions} from './actions';
4 import {Settings} from './settings';
5 import {listen} from './common-events';
6 import {init as initCodemirror} from './codemirror';
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      * @type {MarkdownEditor}
16      */
17     const editor = {
18         config,
19         markdown: new Markdown(),
20         settings: new Settings(config.settingInputs),
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  * @typedef MarkdownEditorConfig
34  * @property {String} pageId
35  * @property {Element} container
36  * @property {Element} displayEl
37  * @property {HTMLTextAreaElement} inputEl
38  * @property {String} drawioUrl
39  * @property {HTMLInputElement[]} settingInputs
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 {EditorView} cm
50  * @property {Settings} settings
51  */