import { __decorate } from "tslib";
import { Component } from 'vue-property-decorator';
import { VueLifeCycleProcessing } from '../../../decorators';
import { EditorBase } from '../editor-base/editor-base';
/**
 * 直接内容编辑器
 *
 * @export
 * @class RawEditor
 * @extends {EditorBase}
 */
let RawEditor = class RawEditor extends EditorBase {
    constructor() {
        super(...arguments);
        /**
         * 直接内容类型
         *
         * @memberof RawEditor
         */
        this.contentType = '';
    }
    /**
     * 编辑器初始化
     *
     * @memberof RawEditor
     */
    async initEditor() {
        var _a;
        await super.initEditor();
        this.contentType = ((_a = this.editorInstance.editorParams) === null || _a === void 0 ? void 0 : _a['CONTENTTYPE']) || 'RAW';
        this.customProps.contentType = this.contentType;
    }
    /**
     * 绘制直接内容的值
     *
     * @memberof RawEditor
     */
    getContentValue(value) {
        const data = this.contextData;
        let content = value;
        if (content) {
            const items = content.match(/\{{(.+?)\}}/g);
            if (items) {
                items.forEach((item) => {
                    content = content.replace(/\{{(.+?)\}}/, eval(item.substring(2, item.length - 2)));
                });
            }
            content = content.replaceAll('&lt;', '<');
            content = content.replaceAll('&gt;', '>');
            content = content.replaceAll('&amp;nbsp;', ' ');
            content = content.replaceAll('&nbsp;', ' ');
        }
        return content;
    }
    /**
     * 绘制内容
     *
     * @returns {*}
     * @memberof RawEditor
     */
    render() {
        if (!this.editorIsLoaded) {
            return null;
        }
        return this.$createElement(this.editorComponentName, {
            props: Object.assign({ content: this.getContentValue(this.value), imgUrl: this.value, itemValue: this.value }, this.customProps),
            style: this.customStyle,
        });
    }
};
RawEditor = __decorate([
    Component({}),
    VueLifeCycleProcessing()
], RawEditor);
export default RawEditor;
