import kindeEditor from "./kindeditor/kindeditor-all";
import "./kindeditor/themes/default/default.scss";
const RichEditor = (($) => {
    const defaultConfig = {
        element: null, 
        text: '', 
        html: '', 
        width: 1017,
        height: 550,
    };
    class RichEditor {
        constructor(config) {
            let _this = this;
            _this._config = _this._getConfig(config);
            _this.editorInstance = kindeEditor.create(_this._config.element, {
                width: _this._config.width + 'px',
                height: _this._config.height + 'px',
                resizeType: 0,
                filterMode: false,
                items: [
                    'undo', 'redo', '|', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'lineheight', '|',
                    'bold', 'italic', 'underline', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|',
                    'link', 'unlink', 'image', 'table', '|', 'preview', 'source'
                ]
            });
            _this.editorInstance.text(_this._config.text);
            _this.editorInstance.html(_this._config.html);
        }
        
        _getConfig(config) {
            if (!config.element) {
                throw Error('必须配置element参数');
            }
            return $.extend({}, defaultConfig, config);
        }
        
        getValue() {
            return this.editorInstance.html();
        }
        
        setValue(value) {
            this.editorInstance.html(value);
        }
        
        dispose() {
            this.editorInstance = null;
        }
    }
    return RichEditor;
})($);
export default RichEditor;