UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

53 lines (52 loc) 2.36 kB
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 __()); }; })(); import React from 'react'; import BaseBraftEditor from 'braft-editor'; import { fontFamilies, extendControls } from './constant'; import zhCN from 'antd/es/locale-provider/zh_CN'; import languageService from '../../../../services/language'; import '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: BaseBraftEditor.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: BaseBraftEditor.createEditorState(nextProps.value) }; } return null; }; BraftEditor.prototype.render = function () { return (React.createElement(BaseBraftEditor, { language: languageService.locale === zhCN.locale ? 'zh' : 'en', fontFamilies: fontFamilies, extendControls: extendControls, imageControls: [], value: this.state.editorState, onChange: this.handleEditorStateChange })); }; return BraftEditor; }(React.Component)); export default BraftEditor;