@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
58 lines (57 loc) • 2.72 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var braft_editor_1 = __importDefault(require("braft-editor"));
var constant_1 = require("./constant");
var zh_CN_1 = __importDefault(require("antd/es/locale-provider/zh_CN"));
var language_1 = __importDefault(require("../../../../services/language"));
require("braft-editor/dist/index.css");
function getEditorStateValue(editorState) {
return editorState.isEmpty() ? '' : editorState.toHTML();
}
var BraftEditor = /** @class */ (function (_super) {
__extends(BraftEditor, _super);
function BraftEditor() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
editorState: braft_editor_1.default.createEditorState(_this.props.value)
};
_this.handleEditorStateChange = function (editorState) {
var _a, _b;
_this.setState({
editorState: editorState
});
(_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, getEditorStateValue(editorState));
};
return _this;
}
BraftEditor.getDerivedStateFromProps = function (nextProps, prevState) {
if (nextProps.value !== getEditorStateValue(prevState.editorState)) {
return {
editorState: braft_editor_1.default.createEditorState(nextProps.value)
};
}
return null;
};
BraftEditor.prototype.render = function () {
return (react_1.default.createElement(braft_editor_1.default, { language: language_1.default.locale === zh_CN_1.default.locale ? 'zh' : 'en', fontFamilies: constant_1.fontFamilies, extendControls: constant_1.extendControls, imageControls: [], value: this.state.editorState, onChange: this.handleEditorStateChange }));
};
return BraftEditor;
}(react_1.default.Component));
exports.default = BraftEditor;