import * as tslib_1 from "tslib";
import React from 'react';
import classNames from 'classnames';
var ContentEditable = (function (_super) {
    tslib_1.__extends(ContentEditable, _super);
    function ContentEditable() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.emitChange = function () {
            var valueType = _this.props.valueType;
            var html = valueType === 'text' ? _this.domNode.innerText : _this.domNode.innerHTML;
            if (_this.props.onChange && html !== _this.lastHtml) {
                _this.props.onChange({
                    target: {
                        value: html,
                    },
                });
            }
            _this.lastHtml = html;
        };
        return _this;
    }
    ContentEditable.prototype.shouldComponentUpdate = function (nextProps) {
        return !!this.domNode && nextProps.html !== this.domNode.innerHTML;
    };
    ContentEditable.prototype.componentDidUpdate = function () {
        var domNode = this.domNode;
        var html = this.props.html;
        if (html && !!domNode && html !== domNode.innerHTML) {
            domNode.innerHTML = html;
        }
    };
    ContentEditable.prototype.render = function () {
        var _this = this;
        var _a = this.props, className = _a.className, style = _a.style, html = _a.html;
        return (React.createElement("div", tslib_1.__assign({ ref: function (dom) { return (_this.domNode = dom); }, onInput: this.emitChange, onBlur: this.emitChange, contentEditable: true, dangerouslySetInnerHTML: { __html: html }, className: classNames('rac_contenteditable', className) }, { style: style })));
    };
    ContentEditable.defaultProps = {
        valueType: 'text',
    };
    return ContentEditable;
}(React.Component));
export default ContentEditable;
//# sourceMappingURL=index.js.map