通用评论

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","setState","onChange","emoji","uid","path","length","forEach","OSS_LINK","item","onSubmit","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;;;;;;;;;;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;AAdiB;AAelB;;;;wCAEmB,CAAE;;AAEtB;;;;;;;;iCAKaJ,K,EAAO;AAClB,WAAKU,QAAL,CAAc,EAAEV,YAAF,EAAd;AACA,UAAI,KAAKH,KAAL,CAAWc,QA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CAAa+C,OAAb,IAAwBnC;AADR,aAA3B,CADD,GAKC;AAAA;AAAA;AACE,yBAAS;AAAA,yBAAM,OAAKA,YAAL,EAAN;AAAA,iBADX;AAEE,sBAAK,SAFP;AAGE,yBAASe,UAHX;AAIE,0BAAUK;AAJZ;AAMGN;AANH;AANJ;AAzEF;AARF,OADF;AAqGD;;;;EAzNkBmB,gBAAMI,S;;AA4N3BlD,OAAOmD,SAAP,GAAmB;AACjB1B,QAAM2B,oBAAUC,MADC;AAEjB7B,eAAa4B,oBAAUE,MAFN;AAGjB5B,aAAW0B,oBAAUG,IAHJ;AAIjBpD,cAAYiD,oBAAUG,IAJL;AAKjBnD,SAAOgD,oBAAUE,MALA;AAMjBvC,YAAUqC,oBAAUI,IANH;AAOjBjC,YAAU6B,oBAAUI,IAPH;AAQjB7B,iBAAeyB,oBAAUE,MARR;AASjB1B,cAAYwB,oBAAUG,IATL;AAUjB1B,eAAauB,oBAAUG,IAVN;AAWjBzB,UAAQsB,oBAAUK,IAXD;AAYjB1B,iBAAeqB,oBAAUK,IAZR;AAajBzB,iBAAeoB,oBAAUK;AAbR,CAAnB;;AAgBAzD,OAAO0D,YAAP,GAAsB;AACpBjC,QAAM,CADc;AAEpBD,eAAa,UAFO;AAGpBE,aAAW,IAHS;AAIpBvB,cAAY,IAJQ;AAKpBwB,iBAAe,IALK;AAMpBC,cAAY,KANQ;AAOpBC,eAAa;AAPO,CAAtB;;kBAUe7B,M","file":"index.js","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Icon, Button, Popover, Input } from 'antd';\nimport { OSS_LINK } from '../../constant';\nimport { MAX_UPLOAD_NUMBER } from '../../constant';\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 }\n\n componentDidMount() {}\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 if (fileList.length) {\n value += '<br/>';\n fileList.forEach(item => {\n value += `[${OSS_LINK}${fileMap[item.uid]}]`;\n });\n }\n this.props.onSubmit(value, () => {\n this.setState({\n showUpload: false,\n value: '',\n fileList: [],\n fileMap: {},\n });\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"]}