{"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","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,CAKC;AALD,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,QAAf,EAAyB;AACvB,aAAK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AAUE,MAFN;AAGjB3B,aAAWyB,oBAAUG,IAHJ;AAIjBnD,cAAYgD,oBAAUG,IAJL;AAKjBlD,SAAO+C,oBAAUE,MALA;AAMjBtC,YAAUoC,oBAAUI,IANH;AAOjBhC,YAAU4B,oBAAUI,IAPH;AAQjB5B,iBAAewB,oBAAUE,MARR;AASjBzB,cAAYuB,oBAAUG,IATL;AAUjBzB,eAAasB,oBAAUG,IAVN;AAWjBxB,UAAQqB,oBAAUK,IAXD;AAYjBzB,iBAAeoB,oBAAUK,IAZR;AAajBxB,iBAAemB,oBAAUK;AAbR,CAAnB;;AAgBAxD,OAAOyD,YAAP,GAAsB;AACpBhC,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 * 上传文件 TODO:\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 += \"
\";\n fileList.forEach(item => {\n value += `[${OSS_LINK}${fileMap[item.uid]}]`;\n });\n }\n this.props.onSubmit(value);\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\n const handleSubmit = this.handleSubmit;\n return (\n
\n this.handleChange(e.target.value)}\n rows={rows}\n placeholder={placeholder}\n />\n\n
\n
\n {showEmoji && (\n \n \n
\n }\n overlayClassName=\"comment-emoji-popover\"\n >\n {emojiToolIcon || (\n \n )}\n \n )}\n\n {showUpload && (\n \n \n
\n }\n placement=\"bottomLeft\"\n title={\n
\n \n 上传图片\n \n (您还能上传{MAX_UPLOAD_NUMBER -\n this.state.fileList.length}张图片)\n \n \n this.handleShowUpload(false)}\n style={{\n float: \"right\",\n cursor: \"pointer\",\n marginTop: 4\n }}\n />\n
\n }\n >\n {imageToolIcon ? (\n React.cloneElement(imageToolIcon, {\n onClick: () => this.handleShowUpload(true)\n })\n ) : (\n this.handleShowUpload(true)}\n />\n )}\n \n )}\n
\n\n
\n {button ? (\n React.cloneElement(button, {\n onClick: button.props.onClick || handleSubmit\n })\n ) : (\n this.handleSubmit()}\n type=\"primary\"\n loading={btnLoading}\n disabled={btnDisabled}\n >\n {btnSubmitText}\n \n )}\n
\n \n \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"]}