mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-11 13:48:13 +03:00
CM6: Updated for popup editor, added new interface
New simple interface added for abstraction of CM editor in simple use-cases, just to provide common actions like get/set content, focus and set mode.
This commit is contained in:
46
resources/js/code/simple-editor-interface.js
Normal file
46
resources/js/code/simple-editor-interface.js
Normal file
@ -0,0 +1,46 @@
|
||||
import {updateViewLanguage} from "./views";
|
||||
|
||||
|
||||
export class SimpleEditorInterface {
|
||||
/**
|
||||
* @param {EditorView} editorView
|
||||
*/
|
||||
constructor(editorView) {
|
||||
this.ev = editorView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of an editor instance.
|
||||
* @return {string}
|
||||
*/
|
||||
getContent() {
|
||||
return this.ev.state.doc.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the contents of an editor instance.
|
||||
* @param content
|
||||
*/
|
||||
setContent(content) {
|
||||
const doc = this.ev.state.doc;
|
||||
this.ev.dispatch({
|
||||
changes: {from: 0, to: doc.length, insert: content}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return focus to the editor instance.
|
||||
*/
|
||||
focus() {
|
||||
this.ev.focus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the language mode of the editor instance.
|
||||
* @param {String} mode
|
||||
* @param {String} content
|
||||
*/
|
||||
setMode(mode, content = '') {
|
||||
updateViewLanguage(this.ev, mode, content);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user