@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
125 lines (124 loc) • 5.67 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import React from 'react';
import classnames from 'classnames';
import BraftEditor from 'braft-editor';
import { observer } from 'mobx-react';
import { computed, reaction } from 'mobx';
import bind from '../../../utils/bind';
import PropTypes from 'prop-types';
import BasicComponent from '../../../components/Base/BasicComponent';
import storeWrapper from '../components/StoreWrapper';
import EditorChartStore from './store';
import { controls } from './constants';
import errorBoundary from '../../../hocs/errorBoundary';
import { formatString } from '../../../services/language';
import { OtherLocale } from '../../../constants/language/other/type';
import 'braft-editor/dist/index.css';
import * as style from './style.mless';
var EditorChart = /** @class */ (function (_super) {
__extends(EditorChart, _super);
function EditorChart() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(EditorChart.prototype, "media", {
get: function () {
return {
accepts: {
video: false,
audio: false
},
externals: {
embed: false
},
validateFn: this.validateFn
};
},
enumerable: false,
configurable: true
});
EditorChart.prototype.validateFn = function (file) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
file.size < 1024 * 1024 * 1
? resolve()
: reject(formatString(OtherLocale.error));
}, 2000);
});
};
EditorChart.prototype.componentDidMount = function () {
var _this = this;
this.props.store.setDditorState(BraftEditor.createEditorState(this.props.store.htmlContent));
this.addDisposer(reaction(function () { return _this.props.store.chartStyleService.htmlContent; }, function () {
var store = _this.props.store;
if (store.htmlContent !== store.chartStyleService.htmlContent) {
store.setDditorState(BraftEditor.createEditorState(store.chartStyleService.htmlContent));
}
}, {
fireImmediately: true
}));
};
EditorChart.prototype.handleEditorChange = function (editorState) {
this.props.store.setDditorState(editorState);
this.props.store.chartStyleService.setHtmlContent(this.props.store.htmlContent);
};
EditorChart.prototype.handleSaveValue = function () {
this.props.store.chartStyleService.setHtmlContent(this.props.store.htmlContent);
};
EditorChart.prototype.render = function () {
var isEdit = this.props.isEdit;
return (React.createElement("div", { className: classnames(style.editorChart) },
React.createElement(BraftEditor, { value: this.props.store.editorState, onChange: this.handleEditorChange, controls: isEdit || !this.context.baseDashboardStore ? controls : [], imageControls: [], onBlur: this.handleSaveValue, readOnly: this.context.baseDashboardStore && !isEdit, media: this.media })));
};
EditorChart.contextTypes = {
baseDashboardStore: PropTypes.object
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], EditorChart.prototype, "media", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [File]),
__metadata("design:returntype", void 0)
], EditorChart.prototype, "validateFn", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], EditorChart.prototype, "handleEditorChange", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], EditorChart.prototype, "handleSaveValue", null);
EditorChart = __decorate([
observer
], EditorChart);
return EditorChart;
}(BasicComponent));
export default errorBoundary(storeWrapper(EditorChart, EditorChartStore));