{"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","handleEmojiScroll","onRef","e","emoji","preventDefault","deltaY","next","prev","setState","onChange","uid","path","map","item","thumbUrl","OSS_LINK","maxLength","length","error","files","forEach","push","beforeSubmit","Promise","resolve","text","then","res","onSubmit","onCommentSuccess","placeholder","rows","showEmoji","closeUploadWhenBlur","maxUpload","btnSubmitText","btnLoading","btnDisabled","button","emojiToolIcon","imageToolIcon","autoFocus","disabledSubmit","inputValue","target","width","node","zIndex","visible","minHeight","margin","showError","onError","color","fontWeight","React","cloneElement","onClick","marginLeft","Component","propTypes","PropTypes","number","string","bool","func","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AACA;;;;AAEA;;;;AACA;;AACA;;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,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;AACA,UAAKM,UAAL,GAA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AS;AAAA,2BAAM,OAAKA,YAAL,EAAN;AAAA,mBADX;AAEE,wBAAK,SAFP;AAGE,2BAASsC,UAHX;AAIE,4BAAUM;AAJZ;AAMGP;AANH;AANJ;AAtGF;AATF;AATF,OADF;AA6ID;;;;EA7TkBoB,gBAAMI,S;;AAgU3B1E,OAAO2E,SAAP,GAAmB;AACjB7B,QAAM8B,oBAAUC,MADC;AAEjBhC,eAAa+B,oBAAUE,MAFN;AAGjB/B,aAAW6B,oBAAUG,IAHJ;AAIjB5E,cAAYyE,oBAAUG,IAJL;AAKjB/B,uBAAqB4B,oBAAUG,IALd;AAMjB9B,aAAW2B,oBAAUC,MANJ;AAOjBzE,SAAOwE,oBAAUE,MAPA;AAQjBtD,YAAUoD,oBAAUI,IARH;AASjBrC,YAAUiC,oBAAUI,IATH;AAUjB3C,gBAAcuC,oBAAUI,IAVP;AAWjB9B,iBAAe0B,oBAAUE,MAXR;AAYjB3B,cAAYyB,oBAAUG,IAZL;AAajB3B,eAAawB,oBAAUG,IAbN;AAcjB1B,UAAQuB,oBAAUf,IAdD;AAejBP,iBAAesB,oBAAUf,IAfR;AAgBjBN,iBAAeqB,oBAAUf,IAhBR;AAiBjBK,aAAWU,oBAAUG,IAjBJ;AAkBjBZ,WAASS,oBAAUI,IAlBF;AAmBjBjD,aAAW6C,oBAAUC;AAnBJ,CAAnB;;AAsBA7E,OAAOiF,YAAP,GAAsB;AACpBnC,QAAM,CADc;AAEpBD,eAAa,UAFO;AAGpBE,aAAW,IAHS;AAIpB5C,cAAY,IAJQ;AAKpB6C,uBAAqB,KALD;AAMpBC,aAAW,CANS;AAOpBC,iBAAe,IAPK;AAQpBC,cAAY,KARQ;AASpBC,eAAa,KATO;AAUpBc,aAAW,IAVS;AAWpBnC,aAAW;AAXS,CAAtB;;kBAce/B,M","file":"index.js","sourcesContent":["import React from \"react\";\nimport PropTypes from \"prop-types\";\nimport { Icon, Button, Popover, Input, message } from \"antd\";\nimport classnames from \"classnames\";\nimport { OSS_LINK } 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 this.handleEmojiScroll = this.handleEmojiScroll.bind(this);\n }\n\n componentDidMount() {\n if (isFunction(this.props.onRef)) {\n this.props.onRef(this);\n }\n }\n\n handleEmojiScroll(e) {\n if (!this.emoji) {\n return;\n }\n e.preventDefault();\n if (e.deltaY > 0) {\n this.emoji.next();\n } else if (e.deltaY < 0) {\n this.emoji.prev();\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 let { fileList } = this.state;\n fileMap[uid] = path;\n fileList = fileList.map(item => {\n if (item.uid === uid) {\n item.thumbUrl = OSS_LINK + path;\n }\n return item;\n });\n this.setState({ fileMap, fileList });\n }\n\n /**\n * 提交编辑器内容\n * 提交功能,交给父组件来实现\n * 需要父组件传入 onSubmit\n */\n handleSubmit() {\n const { maxLength } = this.props;\n let { value, fileMap, fileList } = this.state;\n if (value.length > maxLength) {\n message.error(`字数不得超过${maxLength}字`);\n return;\n }\n const files = [];\n if (fileList.length) {\n fileList.forEach(item => {\n if (!fileMap[item.uid]) {\n return;\n }\n files.push(`${OSS_LINK}${fileMap[item.uid]}`);\n });\n }\n if (this.props.beforeSubmit) {\n Promise.resolve(this.props.beforeSubmit({ text: value, files })).then(\n res => {\n if (!(res === false)) {\n this.props.onSubmit({ text: value, files }, () => {\n this.resetState();\n if (this.props.onCommentSuccess) {\n this.props.onCommentSuccess();\n }\n });\n }\n }\n );\n } else {\n this.props.onSubmit({ text: value, files }, () => {\n this.resetState();\n if (this.props.onCommentSuccess) {\n this.props.onCommentSuccess();\n }\n });\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 closeUploadWhenBlur,\n maxUpload,\n btnSubmitText,\n btnLoading,\n btnDisabled,\n button,\n emojiToolIcon,\n imageToolIcon,\n maxLength,\n autoFocus\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 const inputValue = value || this.state.value;\n return (\n