通用评论

index.js.map 13KB

1
  1. {"version":3,"sources":["../../../src/components/Editor/index.js"],"names":["TextArea","Editor","props","state","showUpload","value","fileList","fileMap","handleChange","bind","handleClickEmoji","handleChangeFileList","handleShowUpload","handleUpload","handleSubmit","resetState","onRef","setState","onChange","emoji","uid","path","files","length","forEach","push","OSS_LINK","item","onSubmit","text","placeholder","rows","showEmoji","btnSubmitText","btnLoading","btnDisabled","button","emojiToolIcon","imageToolIcon","disabledSubmit","e","target","width","zIndex","MAX_UPLOAD_NUMBER","minHeight","margin","color","fontWeight","float","cursor","marginTop","React","cloneElement","onClick","marginLeft","Component","propTypes","PropTypes","number","string","bool","func","node","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;AAEA;;AACA;;;;AACA;;;;AACA;;;;;;;;;;IAEQA,Q,mBAAAA,Q;;IAEFC,M;;;AACJ,kBAAYC,KAAZ,EAAmB;AAAA;;AAAA,gHACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,kBAAY,KADD;AAEXC,aAAO,EAFI,EAEA;;AAEXC,gBAAU,EAJC,EAIG;AACdC,eAAS,EALE,CAKE;AALF,KAAb;AAOA,UAAKC,YAAL,GAAoB,MAAKA,YAAL,CAAkBC,IAAlB,OAApB;AACA,UAAKC,gBAAL,GAAwB,MAAKA,gBAAL,CAAsBD,IAAtB,OAAxB;AACA,UAAKE,oBAAL,GAA4B,MAAKA,oBAAL,CAA0BF,IAA1B,OAA5B;AACA,UAAKG,gBAAL,GAAwB,MAAKA,gBAAL,CAAsBH,IAAtB,OAAxB;AACA,UAAKI,YAAL,GAAoB,MAAKA,YAAL,CAAkBJ,IAAlB,OAApB;AACA,UAAKK,YAAL,GAAoB,MAAKA,YAAL,CAAkBL,IAAlB,OAApB;AACA,UAAKM,UAAL,GAAkB,MAAKA,UAAL,CAAgBN,IAAhB,OAAlB;AAfiB;AAgBlB;;;;wCAEmB;AAClB,UAAI,wBAAW,K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ropTypes from 'prop-types';\nimport { Icon, Button, Popover, Input } from 'antd';\nimport { OSS_LINK } from '../../constant';\nimport { MAX_UPLOAD_NUMBER } from '../../constant';\nimport { isFunction } from '../../helper';\nimport Upload from './Upload';\nimport Emoji from './Emoji';\nimport './index.css';\n\nconst { TextArea } = Input;\n\nclass Editor extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n showUpload: false,\n value: '', // 编辑器里面的值\n\n fileList: [], // 图片列表\n fileMap: {}, // 已经上传的图片路径和 uid 的映射 { uid: path }\n };\n this.handleChange = this.handleChange.bind(this);\n this.handleClickEmoji = this.handleClickEmoji.bind(this);\n this.handleChangeFileList = this.handleChangeFileList.bind(this);\n this.handleShowUpload = this.handleShowUpload.bind(this);\n this.handleUpload = this.handleUpload.bind(this);\n this.handleSubmit = this.handleSubmit.bind(this);\n this.resetState = this.resetState.bind(this);\n }\n\n componentDidMount() {\n if (isFunction(this.props.onRef)) {\n this.props.onRef(this);\n }\n }\n\n /**\n * 编辑器的值改变事件\n * 将最新的值存储到 state 中\n * @param {string} value 输入的值\n */\n handleChange(value) {\n this.setState({ value });\n if (this.props.onChange) {\n this.props.onChange(value);\n }\n }\n\n /**\n * 点击 emoji 的事件\n * 点击后,需要将改 emoji 插入到编辑器中\n * 插入的值为 [emoji chinese name]\n * 参数 emoji 即为 emoji chinese name\n * @param {string}} emoji emoji 的中文,如 微笑\n */\n handleClickEmoji(emoji) {\n let { value } = this.state;\n value += `[${emoji}]`;\n this.handleChange(value);\n }\n\n /**\n * 监听文件列表改变事件\n * @param {Array} fileList 文件列表\n */\n handleChangeFileList(fileList) {\n this.setState({ fileList });\n }\n\n /**\n * 控制上传 Popover 的显示和隐藏\n * @param {boolean} showUpload 是否显示上传的 Popover\n */\n handleShowUpload(showUpload) {\n if (typeof showUpload === 'boolean') {\n this.setState({ showUpload: showUpload });\n } else {\n this.setState({ showUpload: !this.state.showUpload });\n }\n }\n\n /**\n * 上传文件\n * @param {object} param 文件对象\n */\n handleUpload({ uid, path }) {\n const { fileMap } = this.state;\n fileMap[uid] = path;\n this.setState({ fileMap });\n }\n\n /**\n * 提交编辑器内容\n * 提交功能,交给父组件来实现\n * 需要父组件传入 onSubmit\n */\n handleSubmit() {\n let { value, fileMap, fileList } = this.state;\n const files = [];\n if (fileList.length) {\n fileList.forEach(item => {\n files.push(`${OSS_LINK}${fileMap[item.uid]}`);\n });\n }\n this.props.onSubmit({ text: value, files }, () => {\n this.resetState();\n });\n }\n\n resetState() {\n this.setState({\n showUpload: false,\n value: '',\n fileList: [],\n fileMap: {},\n });\n }\n\n render() {\n const {\n value,\n placeholder,\n rows,\n showEmoji,\n showUpload,\n btnSubmitText,\n btnLoading,\n btnDisabled,\n button,\n emojiToolIcon,\n imageToolIcon,\n } = this.props;\n const handleSubmit = this.handleSubmit;\n const disabledSubmit =\n btnDisabled ||\n (!this.props.value && !this.state.value && !this.state.fileList.length);\n return (\n <div className=\"comment-editor\">\n <TextArea\n value={value || this.state.value}\n onChange={e => this.handleChange(e.target.value)}\n rows={rows}\n placeholder={placeholder}\n />\n\n <div className=\"comment-toolbar\">\n <div className=\"comment-toolbar-left\">\n {showEmoji && (\n <Popover\n trigger=\"click\"\n placement=\"bottomLeft\"\n autoAdjustOverflow={false}\n content={\n <div style={{ width: 200 }}>\n <Emoji onClick={this.handleClickEmoji} />\n </div>\n }\n overlayClassName=\"comment-emoji-popover\"\n >\n {emojiToolIcon || (\n <Icon type=\"smile-o\" className=\"comment-toolbar-icon\" />\n )}\n </Popover>\n )}\n\n {showUpload && (\n <Popover\n visible={this.state.showUpload}\n overlayStyle={{ zIndex: 999 }}\n content={\n <div\n style={{ width: 112 * MAX_UPLOAD_NUMBER, minHeight: 100 }}\n >\n <Upload\n onChangeFileList={this.handleChangeFileList}\n onUpload={this.handleUpload}\n fileList={this.state.fileList}\n />\n </div>\n }\n placement=\"bottomLeft\"\n title={\n <div style={{ margin: '5px auto' }}>\n <span>\n 上传图片\n <span style={{ color: '#666', fontWeight: 400 }}>\n (您还能上传{MAX_UPLOAD_NUMBER -\n this.state.fileList.length}张图片)\n </span>\n </span>\n <Icon\n type=\"close\"\n onClick={() => this.handleShowUpload(false)}\n style={{\n float: 'right',\n cursor: 'pointer',\n marginTop: 4,\n }}\n />\n </div>\n }\n >\n {imageToolIcon ? (\n React.cloneElement(imageToolIcon, {\n onClick: () => this.handleShowUpload(true),\n })\n ) : (\n <Icon\n type=\"picture\"\n className=\"comment-toolbar-icon\"\n style={{ marginLeft: 10 }}\n onClick={() => this.handleShowUpload(true)}\n />\n )}\n </Popover>\n )}\n </div>\n\n <div className=\"comment-toolbar-right\">\n {button ? (\n React.cloneElement(button, {\n onClick: button.props.onClick || handleSubmit,\n })\n ) : (\n <Button\n onClick={() => this.handleSubmit()}\n type=\"primary\"\n loading={btnLoading}\n disabled={disabledSubmit}\n >\n {btnSubmitText}\n </Button>\n )}\n </div>\n </div>\n </div>\n );\n }\n}\n\nEditor.propTypes = {\n rows: PropTypes.number,\n placeholder: PropTypes.string,\n showEmoji: PropTypes.bool,\n showUpload: PropTypes.bool,\n value: PropTypes.string,\n onChange: PropTypes.func,\n onSubmit: PropTypes.func,\n btnSubmitText: PropTypes.string,\n btnLoading: PropTypes.bool,\n btnDisabled: PropTypes.bool,\n button: PropTypes.node,\n emojiToolIcon: PropTypes.node,\n imageToolIcon: PropTypes.node,\n};\n\nEditor.defaultProps = {\n rows: 5,\n placeholder: '说点什么吧...',\n showEmoji: true,\n showUpload: true,\n btnSubmitText: '发表',\n btnLoading: false,\n btnDisabled: false,\n};\n\nexport default Editor;\n"]}