2022-11-26 16:43:28 +00:00
|
|
|
import {Markdown} from "./markdown";
|
|
|
|
import {Display} from "./display";
|
|
|
|
import {Actions} from "./actions";
|
2022-11-28 12:12:36 +00:00
|
|
|
import {Settings} from "./settings";
|
2022-11-26 16:43:28 +00:00
|
|
|
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(),
|
2022-11-28 12:12:36 +00:00
|
|
|
settings: new Settings(config.settings),
|
2022-11-26 16:43:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2022-11-28 12:12:36 +00:00
|
|
|
* @property {Object<String, any>} settings
|
2022-11-26 16:43:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef MarkdownEditor
|
|
|
|
* @property {MarkdownEditorConfig} config
|
|
|
|
* @property {Display} display
|
|
|
|
* @property {Markdown} markdown
|
|
|
|
* @property {Actions} actions
|
|
|
|
* @property {CodeMirror} cm
|
2022-11-28 12:12:36 +00:00
|
|
|
* @property {Settings} settings
|
2022-11-26 16:43:28 +00:00
|
|
|
*/
|