2018-10-03 12:26:41 +03:00
|
|
|
import CodeXEditor from 'codex.editor';
|
2019-02-15 17:56:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tools for the Editor
|
|
|
|
*/
|
2018-10-04 22:08:21 +03:00
|
|
|
import Header from 'codex.editor.header';
|
2019-02-15 17:56:56 +03:00
|
|
|
import Quote from 'codex.editor.quote';
|
|
|
|
import Marker from 'codex.editor.marker';
|
2018-10-20 17:54:15 +03:00
|
|
|
import CodeTool from 'codex.editor.code';
|
2019-02-15 17:56:56 +03:00
|
|
|
import Delimiter from 'codex.editor.delimiter';
|
2018-10-20 17:54:15 +03:00
|
|
|
import InlineCode from 'codex.editor.inline-code';
|
2019-02-15 17:56:56 +03:00
|
|
|
import List from 'codex.editor.list';
|
|
|
|
import RawTool from 'codex.editor.raw';
|
|
|
|
import Embed from 'codex.editor.embed';
|
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
|
2019-02-15 17:56:56 +03:00
|
|
|
* @param {object} editorConfig - configuration object for Editor.js
|
|
|
|
* @param {object} data.blocks - data to start with
|
|
|
|
* @param {object} options
|
|
|
|
* @param {string} options.headerPlaceholder - placeholder for Header tool
|
2018-10-04 22:08:21 +03:00
|
|
|
*/
|
2019-02-15 17:56:56 +03:00
|
|
|
constructor(editorConfig = {}, options = {}) {
|
|
|
|
const defaultConfig = {
|
2018-10-04 22:08:21 +03:00
|
|
|
tools: {
|
|
|
|
header: {
|
|
|
|
class: Header,
|
2019-02-15 17:56:56 +03:00
|
|
|
inlineToolbar: ['link', 'marker'],
|
2018-10-04 22:08:21 +03:00
|
|
|
config: {
|
2019-02-15 17:56:56 +03:00
|
|
|
placeholder: options.headerPlaceholder || ''
|
2018-10-04 22:08:21 +03:00
|
|
|
}
|
2018-10-20 17:54:15 +03:00
|
|
|
},
|
2019-02-15 17:56:56 +03:00
|
|
|
// image: {
|
|
|
|
// class: ImageTool,
|
|
|
|
// inlineToolbar: true,
|
|
|
|
// config: {
|
|
|
|
// endpoints: {
|
|
|
|
// byFile: '/editor/transport',
|
|
|
|
// byUrl: '/editor/transport'
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
list: {
|
|
|
|
class: List,
|
|
|
|
inlineToolbar: true
|
|
|
|
},
|
|
|
|
quote: {
|
|
|
|
class: Quote,
|
|
|
|
inlineToolbar: true
|
|
|
|
},
|
|
|
|
code: {
|
|
|
|
class: CodeTool,
|
|
|
|
shortcut: 'CMD+SHIFT+D'
|
|
|
|
},
|
|
|
|
rawTool: {
|
|
|
|
class: RawTool,
|
|
|
|
shortcut: 'CMD+SHIFT+R'
|
2018-10-20 17:54:15 +03:00
|
|
|
},
|
2019-02-18 10:42:12 +03:00
|
|
|
delimiter: Delimiter,
|
|
|
|
embed: Embed,
|
|
|
|
inlineCode: {
|
|
|
|
class: InlineCode,
|
|
|
|
shortcut: 'CMD+SHIFT+C'
|
|
|
|
},
|
2019-02-15 17:56:56 +03:00
|
|
|
marker: {
|
2018-10-20 17:54:15 +03:00
|
|
|
class: Marker,
|
|
|
|
shortcut: 'CMD+SHIFT+M'
|
2019-02-18 10:42:12 +03:00
|
|
|
}
|
2018-10-04 22:08:21 +03:00
|
|
|
},
|
2019-02-15 17:56:56 +03:00
|
|
|
data: {
|
2018-10-04 22:08:21 +03:00
|
|
|
blocks: [
|
|
|
|
{
|
|
|
|
type: 'header',
|
|
|
|
data: {
|
|
|
|
text: '',
|
|
|
|
level: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-02-15 17:56:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.editor = new CodeXEditor(Object.assign(defaultConfig, editorConfig));
|
2018-10-04 22:08:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return Editor data
|
|
|
|
* @return {Promise.<{}>}
|
|
|
|
*/
|
|
|
|
save() {
|
|
|
|
return this.editor.saver.save();
|
2018-10-03 12:26:41 +03:00
|
|
|
}
|
|
|
|
}
|