]> BookStack Code Mirror - bookstack/blob - resources/js/markdown/editor.js
Converted md settings to localstorage, added preview resize
[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 /**
10  * Initiate a new markdown editor instance.
11  * @param {MarkdownEditorConfig} config
12  * @returns {Promise<MarkdownEditor>}
13  */
14 export async function init(config) {
15
16     /**
17      * @type {MarkdownEditor}
18      */
19     const editor = {
20         config,
21         markdown: new Markdown(),
22         settings: new Settings(config.settingInputs),
23     };
24
25     editor.actions = new Actions(editor);
26     editor.display = new Display(editor);
27     editor.cm = await initCodemirror(editor);
28
29     listen(editor);
30
31     return editor;
32 }
33
34
35 /**
36  * @typedef MarkdownEditorConfig
37  * @property {String} pageId
38  * @property {Element} container
39  * @property {Element} displayEl
40  * @property {HTMLTextAreaElement} inputEl
41  * @property {String} drawioUrl
42  * @property {HTMLInputElement[]} settingInputs
43  * @property {Object<String, String>} text
44  */
45
46 /**
47  * @typedef MarkdownEditor
48  * @property {MarkdownEditorConfig} config
49  * @property {Display} display
50  * @property {Markdown} markdown
51  * @property {Actions} actions
52  * @property {CodeMirror} cm
53  * @property {Settings} settings
54  */