123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
-
- var _button = require('antd/es/button');
-
- var _button2 = _interopRequireDefault(_button);
-
- var _popover = require('antd/es/popover');
-
- var _popover2 = _interopRequireDefault(_popover);
-
- var _icon = require('antd/es/icon');
-
- var _icon2 = _interopRequireDefault(_icon);
-
- var _input = require('antd/es/input');
-
- var _input2 = _interopRequireDefault(_input);
-
- 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; }; }();
-
- require('antd/es/button/style/css');
-
- require('antd/es/popover/style/css');
-
- require('antd/es/icon/style/css');
-
- require('antd/es/input/style/css');
-
- var _react = require('react');
-
- var _react2 = _interopRequireDefault(_react);
-
- var _propTypes = require('prop-types');
-
- var _propTypes2 = _interopRequireDefault(_propTypes);
-
- var _constant = require('../../constant');
-
- var _Upload = require('./Upload');
-
- var _Upload2 = _interopRequireDefault(_Upload);
-
- var _Emoji = require('./Emoji');
-
- var _Emoji2 = _interopRequireDefault(_Emoji);
-
- require('./index.css');
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- 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; }
-
- var TextArea = _input2.default.TextArea;
-
- var Editor = function (_React$Component) {
- _inherits(Editor, _React$Component);
-
- function Editor(props) {
- _classCallCheck(this, Editor);
-
- var _this = _possibleConstructorReturn(this, (Editor.__proto__ || Object.getPrototypeOf(Editor)).call(this, props));
-
- _this.state = {
- showUpload: false,
- value: '', // 编辑器里面的值
-
- fileList: [], // 图片列表
- fileMap: {} // 已经上传的图片路径和 uid 的映射 { uid: path }
- };
- _this.handleChange = _this.handleChange.bind(_this);
- _this.handleClickEmoji = _this.handleClickEmoji.bind(_this);
- _this.handleChangeFileList = _this.handleChangeFileList.bind(_this);
- _this.handleShowUpload = _this.handleShowUpload.bind(_this);
- _this.handleUpload = _this.handleUpload.bind(_this);
- _this.handleSubmit = _this.handleSubmit.bind(_this);
- return _this;
- }
-
- _createClass(Editor, [{
- key: 'componentDidMount',
- value: function componentDidMount() {}
-
- /**
- * 编辑器的值改变事件
- * 将最新的值存储到 state 中
- * @param {string} value 输入的值
- */
-
- }, {
- key: 'handleChange',
- value: function handleChange(value) {
- this.setState({ value: value });
- if (this.props.onChange) {
- this.props.onChange(value);
- }
- }
-
- /**
- * 点击 emoji 的事件
- * 点击后,需要将改 emoji 插入到编辑器中
- * 插入的值为 [emoji chinese name]
- * 参数 emoji 即为 emoji chinese name
- * @param {string}} emoji emoji 的中文,如 微笑
- */
-
- }, {
- key: 'handleClickEmoji',
- value: function handleClickEmoji(emoji) {
- var value = this.state.value;
-
- value += '[' + emoji + ']';
- this.handleChange(value);
- }
-
- /**
- * 监听文件列表改变事件
- * @param {Array} fileList 文件列表
- */
-
- }, {
- key: 'handleChangeFileList',
- value: function handleChangeFileList(fileList) {
- this.setState({ fileList: fileList });
- }
-
- /**
- * 控制上传 Popover 的显示和隐藏
- * @param {boolean} showUpload 是否显示上传的 Popover
- */
-
- }, {
- key: 'handleShowUpload',
- value: function handleShowUpload(showUpload) {
- if (typeof showUpload === 'boolean') {
- this.setState({ showUpload: showUpload });
- } else {
- this.setState({ showUpload: !this.state.showUpload });
- }
- }
-
- /**
- * 上传文件 TODO:
- * @param {object} param 文件对象
- */
-
- }, {
- key: 'handleUpload',
- value: function handleUpload(_ref) {
- var uid = _ref.uid,
- path = _ref.path;
- var fileMap = this.state.fileMap;
-
- fileMap[uid] = path;
- this.setState({ fileMap: fileMap });
- }
-
- /**
- * 提交编辑器内容
- * 提交功能,交给父组件来实现
- * 需要父组件传入 onSubmit
- */
-
- }, {
- key: 'handleSubmit',
- value: function handleSubmit() {
- var _state = this.state,
- value = _state.value,
- fileMap = _state.fileMap,
- fileList = _state.fileList;
-
- if (fileList.length) {
- value += '<br/>';
- fileList.forEach(function (item) {
- value += '[' + _constant.OSS_LINK + fileMap[item.uid] + ']';
- });
- }
- this.props.onSubmit(value);
- }
- }, {
- key: 'render',
- value: function render() {
- var _this2 = this;
-
- var _props = this.props,
- value = _props.value,
- placeholder = _props.placeholder,
- rows = _props.rows,
- showEmoji = _props.showEmoji,
- showUpload = _props.showUpload,
- btnSubmitText = _props.btnSubmitText,
- btnLoading = _props.btnLoading,
- btnDisabled = _props.btnDisabled,
- button = _props.button,
- emojiToolIcon = _props.emojiToolIcon,
- imageToolIcon = _props.imageToolIcon;
-
-
- var handleSubmit = this.handleSubmit;
- return _react2.default.createElement(
- 'div',
- { className: 'editor' },
- _react2.default.createElement(TextArea, {
- value: value || this.state.value,
- onChange: function onChange(e) {
- return _this2.handleChange(e.target.value);
- },
- rows: rows,
- placeholder: placeholder
- }),
- _react2.default.createElement(
- 'div',
- { className: 'toolbar' },
- _react2.default.createElement(
- 'div',
- { style: { float: 'left', margin: '8px 11px' } },
- showEmoji && _react2.default.createElement(
- _popover2.default,
- {
- trigger: 'click',
- placement: 'bottomLeft',
- autoAdjustOverflow: false,
- content: _react2.default.createElement(
- 'div',
- { style: { width: 200 } },
- _react2.default.createElement(_Emoji2.default, { onClick: this.handleClickEmoji })
- ),
- overlayClassName: 'feed'
- },
- emojiToolIcon || _react2.default.createElement(_icon2.default, { type: 'smile-o', className: 'icon' })
- ),
- showUpload && _react2.default.createElement(
- _popover2.default,
- {
- visible: this.state.showUpload,
- overlayStyle: { zIndex: 999 },
- content: _react2.default.createElement(
- 'div',
- {
- style: { width: 112 * _constant.MAX_UPLOAD_NUMBER, minHeight: 100 }
- },
- _react2.default.createElement(_Upload2.default, {
- onChangeFileList: this.handleChangeFileList,
- onUpload: this.handleUpload,
- fileList: this.state.fileList
- })
- ),
- placement: 'bottomLeft',
- title: _react2.default.createElement(
- 'div',
- { style: { margin: '5px auto' } },
- _react2.default.createElement(
- 'span',
- null,
- '\u4E0A\u4F20\u56FE\u7247',
- _react2.default.createElement(
- 'span',
- { style: { color: '#666', fontWeight: 400 } },
- '(\u60A8\u8FD8\u80FD\u4E0A\u4F20',
- _constant.MAX_UPLOAD_NUMBER - this.state.fileList.length,
- '\u5F20\u56FE\u7247)'
- )
- ),
- _react2.default.createElement(_icon2.default, {
- type: 'close',
- onClick: function onClick() {
- return _this2.handleShowUpload(false);
- },
- style: {
- float: 'right',
- cursor: 'pointer',
- marginTop: 4
- }
- })
- )
- },
- imageToolIcon ? _react2.default.cloneElement(imageToolIcon, {
- onClick: function onClick() {
- return _this2.handleShowUpload(true);
- }
- }) : _react2.default.createElement(_icon2.default, {
- type: 'picture',
- className: 'icon',
- style: { marginLeft: 10 },
- onClick: function onClick() {
- return _this2.handleShowUpload(true);
- }
- })
- )
- ),
- _react2.default.createElement(
- 'div',
- { style: { float: 'right', margin: '5px 11px' } },
- button ? _react2.default.cloneElement(button, {
- onClick: button.props.onClick || handleSubmit
- }) : _react2.default.createElement(
- _button2.default,
- {
- onClick: function onClick() {
- return _this2.handleSubmit();
- },
- type: 'primary',
- loading: btnLoading,
- disabled: btnDisabled
- },
- btnSubmitText
- )
- )
- )
- );
- }
- }]);
-
- return Editor;
- }(_react2.default.Component);
-
- Editor.propTypes = {
- rows: _propTypes2.default.number,
- placeholder: _propTypes2.default.string,
- showEmoji: _propTypes2.default.bool,
- showUpload: _propTypes2.default.bool,
- value: _propTypes2.default.string,
- onChange: _propTypes2.default.func,
- onSubmit: _propTypes2.default.func,
- btnSubmitText: _propTypes2.default.string,
- btnLoading: _propTypes2.default.bool,
- btnDisabled: _propTypes2.default.bool,
- button: _propTypes2.default.node,
- emojiToolIcon: _propTypes2.default.node,
- imageToolIcon: _propTypes2.default.node
- };
-
- Editor.defaultProps = {
- rows: 5,
- placeholder: '说点什么吧...',
- showEmoji: true,
- showUpload: true,
- btnSubmitText: '发表',
- btnLoading: false,
- btnDisabled: false
- };
-
- exports.default = Editor;
- //# sourceMappingURL=index.js.map
|