通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _button = require("antd/es/button");
  6. var _button2 = _interopRequireDefault(_button);
  7. var _popover = require("antd/es/popover");
  8. var _popover2 = _interopRequireDefault(_popover);
  9. var _icon = require("antd/es/icon");
  10. var _icon2 = _interopRequireDefault(_icon);
  11. var _input = require("antd/es/input");
  12. var _input2 = _interopRequireDefault(_input);
  13. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14. 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; }; }();
  15. require("antd/es/button/style/css");
  16. require("antd/es/popover/style/css");
  17. require("antd/es/icon/style/css");
  18. require("antd/es/input/style/css");
  19. var _react = require("react");
  20. var _react2 = _interopRequireDefault(_react);
  21. var _propTypes = require("prop-types");
  22. var _propTypes2 = _interopRequireDefault(_propTypes);
  23. var _constant = require("../../constant");
  24. var _Upload = require("./Upload");
  25. var _Upload2 = _interopRequireDefault(_Upload);
  26. var _Emoji = require("./Emoji");
  27. var _Emoji2 = _interopRequireDefault(_Emoji);
  28. require("./index.css");
  29. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31. 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; }
  32. 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; }
  33. var TextArea = _input2.default.TextArea;
  34. // 设置 Editor 组件的默认值
  35. // 不能在 Editor.defaultProps 中设置
  36. // 因为 Editor 在 ComponentInput 中调用
  37. // 在 ComponentInput 中,需要使用 Editor 的 props 覆盖 ComponentInput 传入的 props
  38. var EditorDefaultProps = {
  39. rows: 5,
  40. placeholder: "说点什么吧...",
  41. showEmoji: true,
  42. showUpload: true,
  43. submitText: "发表",
  44. onChange: function onChange() {}
  45. };
  46. var Editor = function (_React$Component) {
  47. _inherits(Editor, _React$Component);
  48. function Editor(props) {
  49. _classCallCheck(this, Editor);
  50. var _this = _possibleConstructorReturn(this, (Editor.__proto__ || Object.getPrototypeOf(Editor)).call(this, props));
  51. _this.state = {
  52. showUpload: false
  53. };
  54. _this.handleClickEmoji = _this.handleClickEmoji.bind(_this);
  55. _this.handleShowUpload = _this.handleShowUpload.bind(_this);
  56. return _this;
  57. }
  58. _createClass(Editor, [{
  59. key: "componentDidMount",
  60. value: function componentDidMount() {}
  61. }, {
  62. key: "handleClickEmoji",
  63. value: function handleClickEmoji(emojiId) {
  64. this.props.onChangeEmoji(emojiId);
  65. }
  66. }, {
  67. key: "handleShowUpload",
  68. value: function handleShowUpload(showUpload) {
  69. if (typeof showUpload === "boolean") {
  70. this.setState({ showUpload: showUpload });
  71. } else {
  72. this.setState({ showUpload: !this.state.showUpload });
  73. }
  74. }
  75. }, {
  76. key: "render",
  77. value: function render() {
  78. var _this2 = this;
  79. var props = _extends({}, EditorDefaultProps, this.props);
  80. var value = props.value,
  81. _onChange = props.onChange,
  82. onSubmit = props.onSubmit,
  83. loading = props.loading,
  84. placeholder = props.placeholder,
  85. fileList = props.fileList,
  86. onChangeFileList = props.onChangeFileList,
  87. rows = props.rows,
  88. onUpload = props.onUpload,
  89. showEmoji = props.showEmoji,
  90. showUpload = props.showUpload,
  91. submitText = props.submitText;
  92. return _react2.default.createElement(
  93. "div",
  94. { className: "editor" },
  95. _react2.default.createElement(TextArea, {
  96. value: value,
  97. onChange: function onChange(e) {
  98. return _onChange(e.target.value);
  99. },
  100. rows: rows,
  101. placeholder: placeholder
  102. }),
  103. _react2.default.createElement(
  104. "div",
  105. { className: "toolbar" },
  106. _react2.default.createElement(
  107. "div",
  108. { style: { float: "left", margin: "8px 11px" } },
  109. showEmoji && _react2.default.createElement(
  110. _popover2.default,
  111. {
  112. trigger: "click",
  113. placement: "bottomLeft",
  114. autoAdjustOverflow: false,
  115. content: _react2.default.createElement(
  116. "div",
  117. { style: { width: 200 } },
  118. _react2.default.createElement(_Emoji2.default, { onClick: this.handleClickEmoji })
  119. ),
  120. overlayClassName: "feed"
  121. },
  122. _react2.default.createElement(_icon2.default, { type: "smile-o", className: "icon" })
  123. ),
  124. showUpload && _react2.default.createElement(
  125. _popover2.default,
  126. {
  127. visible: this.state.showUpload,
  128. overlayStyle: { zIndex: 999 },
  129. content: _react2.default.createElement(
  130. "div",
  131. {
  132. style: { width: 112 * _constant.MAX_UPLOAD_NUMBER, minHeight: 100 }
  133. },
  134. _react2.default.createElement(_Upload2.default, {
  135. onChangeFileList: onChangeFileList,
  136. onUpload: onUpload,
  137. fileList: fileList
  138. })
  139. ),
  140. placement: "bottomLeft",
  141. title: _react2.default.createElement(
  142. "div",
  143. { style: { margin: "5px auto" } },
  144. _react2.default.createElement(
  145. "span",
  146. null,
  147. "\u4E0A\u4F20\u56FE\u7247",
  148. _react2.default.createElement(
  149. "span",
  150. { style: { color: "#666", fontWeight: 400 } },
  151. "(\u60A8\u8FD8\u80FD\u4E0A\u4F20",
  152. _constant.MAX_UPLOAD_NUMBER - fileList.length,
  153. "\u5F20\u56FE\u7247)"
  154. )
  155. ),
  156. _react2.default.createElement(_icon2.default, {
  157. type: "close",
  158. onClick: function onClick() {
  159. return _this2.handleShowUpload(false);
  160. },
  161. style: {
  162. float: "right",
  163. cursor: "pointer",
  164. marginTop: 4
  165. }
  166. })
  167. )
  168. },
  169. _react2.default.createElement(_icon2.default, {
  170. type: "picture",
  171. className: "icon",
  172. style: { marginLeft: 10 },
  173. onClick: function onClick() {
  174. return _this2.handleShowUpload(true);
  175. }
  176. })
  177. )
  178. ),
  179. _react2.default.createElement(
  180. "div",
  181. { style: { float: "right", margin: "5px 11px" } },
  182. _react2.default.createElement(
  183. _button2.default,
  184. { onClick: onSubmit, type: "primary", loading: loading },
  185. submitText
  186. )
  187. )
  188. )
  189. );
  190. }
  191. }]);
  192. return Editor;
  193. }(_react2.default.Component);
  194. Editor.propTypes = {
  195. rows: _propTypes2.default.number,
  196. placeholder: _propTypes2.default.string,
  197. showEmoji: _propTypes2.default.bool,
  198. showUpload: _propTypes2.default.bool,
  199. submitText: _propTypes2.default.string,
  200. onChange: _propTypes2.default.func
  201. };
  202. exports.default = Editor;
  203. //# sourceMappingURL=index.js.map