2018-10-03 12:26:41 +03:00
|
|
|
import CodeXEditor from 'codex.editor';
|
2018-10-04 22:08:21 +03:00
|
|
|
import Header from 'codex.editor.header';
|
2018-10-20 17:54:15 +03:00
|
|
|
import CodeTool from 'codex.editor.code';
|
|
|
|
import InlineCode from 'codex.editor.inline-code';
|
|
|
|
import Marker from 'codex.editor.marker';
|
|
|
|
import ListTool from 'codex.editor.list';
|
2018-10-03 12:26:41 +03:00
|
|
|
|
2018-10-04 22:08:21 +03:00
|
|
|
/**
|
|
|
|
* Class for working with Editor.js
|
|
|
|
*/
|
2018-10-03 12:26:41 +03:00
|
|
|
export default class Editor {
|
2018-10-04 22:08:21 +03:00
|
|
|
/**
|
|
|
|
* Creates Editor instance
|
2018-10-15 22:06:01 +03:00
|
|
|
* @property {object} initialData - data to start with
|
2018-10-04 22:08:21 +03:00
|
|
|
*/
|
2018-10-15 22:06:01 +03:00
|
|
|
constructor({initialData}) {
|
2018-10-04 22:08:21 +03:00
|
|
|
this.editor = new CodeXEditor({
|
|
|
|
tools: {
|
|
|
|
header: {
|
|
|
|
class: Header,
|
|
|
|
config: {
|
|
|
|
placeholder: 'Enter a title'
|
|
|
|
}
|
2018-10-20 17:54:15 +03:00
|
|
|
},
|
|
|
|
code: CodeTool,
|
|
|
|
inlineCode: {
|
|
|
|
class: InlineCode,
|
|
|
|
shortcut: 'CMD+SHIFT+I'
|
|
|
|
},
|
|
|
|
Marker: {
|
|
|
|
class: Marker,
|
|
|
|
shortcut: 'CMD+SHIFT+M'
|
|
|
|
},
|
|
|
|
list: {
|
|
|
|
class: ListTool,
|
|
|
|
inlineToolbar: true
|
2018-10-04 22:08:21 +03:00
|
|
|
}
|
|
|
|
},
|
2018-10-15 22:06:01 +03:00
|
|
|
data: initialData || {
|
2018-10-04 22:08:21 +03:00
|
|
|
blocks: [
|
|
|
|
{
|
|
|
|
type: 'header',
|
|
|
|
data: {
|
|
|
|
text: '',
|
|
|
|
level: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return Editor data
|
|
|
|
* @return {Promise.<{}>}
|
|
|
|
*/
|
|
|
|
save() {
|
|
|
|
return this.editor.saver.save();
|
2018-10-03 12:26:41 +03:00
|
|
|
}
|
|
|
|
}
|