kf-slate-editor
Version:
Another rich text editor using Slate framework with toolbar support
99 lines (74 loc) • 5.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var React = _interopRequireWildcard(_react);
var _reactDropzone = require('react-dropzone');
var _reactDropzone2 = _interopRequireDefault(_reactDropzone);
var _imageCompressor = require('image-compressor.js');
var _imageCompressor2 = _interopRequireDefault(_imageCompressor);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* Created by zhangliqing on 2018/5/18.
*/
var Image = function (_React$Component) {
_inherits(Image, _React$Component);
function Image(props) {
_classCallCheck(this, Image);
var _this = _possibleConstructorReturn(this, (Image.__proto__ || Object.getPrototypeOf(Image)).call(this, props));
_this.state = { imageBase64Files: [] };
return _this;
}
_createClass(Image, [{
key: 'handleDrop',
value: function handleDrop(imageFiles) {
var _this2 = this;
var imageBase64Files = new Array();
imageFiles.forEach(function (file) {
new _imageCompressor2.default(file, {
quality: 0.6,
success: function success(result) {
var reader = new FileReader();
reader.readAsDataURL(result);
reader.onloadend = function () {
var base64data = reader.result;
imageBase64Files.push(base64data);
_this2.setState({ imageBase64Files: imageBase64Files });
};
},
error: function error(e) {
console.log(e.message);
}
});
});
}
}, {
key: 'render',
value: function render() {
var imageBase64Files = this.state.imageBase64Files;
return React.createElement(
'section',
null,
imageBase64Files.length === 0 && React.createElement(
_reactDropzone2.default,
{ onDrop: this.handleDrop.bind(this) },
'\u62D6\u62FD\u6216\u70B9\u51FB\u4E0A\u4F20'
),
imageBase64Files.length > 0 && React.createElement(
'div',
null,
imageBase64Files.map(function (base, i) {
return React.createElement('img', { src: base, key: i, style: { margin: "10px auto", maxWidth: "100%" } });
})
)
);
}
}]);
return Image;
}(React.Component);
exports.default = Image;