{"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","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","e","target","width","zIndex","visible","minHeight","margin","showError","onError","color","fontWeight","float","cursor","marginTop","React","cloneElement","onClick","marginLeft","Component","propTypes","PropTypes","number","string","bool","func","node","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,GAAkB,MAAKA,UAAL,C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akC,oBAAUE,MAFN;AAGjBlC,aAAWgC,oBAAUG,IAHJ;AAIjBzE,cAAYsE,oBAAUG,IAJL;AAKjBlC,uBAAqB+B,oBAAUG,IALd;AAMjBjC,aAAW8B,oBAAUC,MANJ;AAOjBtE,SAAOqE,oBAAUE,MAPA;AAQjB1D,YAAUwD,oBAAUI,IARH;AASjBxC,YAAUoC,oBAAUI,IATH;AAUjB9C,gBAAc0C,oBAAUI,IAVP;AAWjBjC,iBAAe6B,oBAAUE,MAXR;AAYjB9B,cAAY4B,oBAAUG,IAZL;AAajB9B,eAAa2B,oBAAUG,IAbN;AAcjB7B,UAAQ0B,oBAAUK,IAdD;AAejB9B,iBAAeyB,oBAAUK,IAfR;AAgBjB7B,iBAAewB,oBAAUK,IAhBR;AAiBjBlB,aAAWa,oBAAUG,IAjBJ;AAkBjBf,WAASY,oBAAUI,IAlBF;AAmBjBpD,aAAWgD,oBAAUC;AAnBJ,CAAnB;;AAsBA1E,OAAO+E,YAAP,GAAsB;AACpBvC,QAAM,CADc;AAEpBD,eAAa,UAFO;AAGpBE,aAAW,IAHS;AAIpBtC,cAAY,IAJQ;AAKpBuC,uBAAqB,KALD;AAMpBC,aAAW,CANS;AAOpBC,iBAAe,IAPK;AAQpBC,cAAY,KARQ;AASpBC,eAAa,KATO;AAUpBc,aAAW,IAVS;AAWpBnC,aAAW;AAXS,CAAtB;;kBAcezB,M","file":"index.js","sourcesContent":["import React from \"react\";\r\nimport PropTypes from \"prop-types\";\r\nimport { Icon, Button, Popover, Input, message } from \"antd\";\r\nimport classnames from \"classnames\";\r\nimport { OSS_LINK } from \"../../constant\";\r\nimport { isFunction } from \"../../helper\";\r\nimport Upload from \"./Upload\";\r\nimport Emoji from \"./Emoji\";\r\nimport \"./index.css\";\r\n\r\nconst { TextArea } = Input;\r\n\r\nclass Editor extends React.Component {\r\n constructor(props) {\r\n super(props);\r\n this.state = {\r\n showUpload: false,\r\n value: \"\", // 编辑器里面的值\r\n\r\n fileList: [], // 图片列表\r\n fileMap: {} // 已经上传的图片路径和 uid 的映射 { uid: path }\r\n };\r\n this.handleChange = this.handleChange.bind(this);\r\n this.handleClickEmoji = this.handleClickEmoji.bind(this);\r\n this.handleChangeFileList = this.handleChangeFileList.bind(this);\r\n this.handleShowUpload = this.handleShowUpload.bind(this);\r\n this.handleUpload = this.handleUpload.bind(this);\r\n this.handleSubmit = this.handleSubmit.bind(this);\r\n this.resetState = this.resetState.bind(this);\r\n }\r\n\r\n componentDidMount() {\r\n if (isFunction(this.props.onRef)) {\r\n this.props.onRef(this);\r\n }\r\n }\r\n\r\n /**\r\n * 编辑器的值改变事件\r\n * 将最新的值存储到 state 中\r\n * @param {string} value 输入的值\r\n */\r\n handleChange(value) {\r\n this.setState({ value });\r\n if (this.props.onChange) {\r\n this.props.onChange(value);\r\n }\r\n }\r\n\r\n /**\r\n * 点击 emoji 的事件\r\n * 点击后,需要将改 emoji 插入到编辑器中\r\n * 插入的值为 [emoji chinese name]\r\n * 参数 emoji 即为 emoji chinese name\r\n * @param {string}} emoji emoji 的中文,如 微笑\r\n */\r\n handleClickEmoji(emoji) {\r\n let { value } = this.state;\r\n value += `[${emoji}]`;\r\n this.handleChange(value);\r\n }\r\n\r\n /**\r\n * 监听文件列表改变事件\r\n * @param {Array} fileList 文件列表\r\n */\r\n handleChangeFileList(fileList) {\r\n this.setState({ fileList });\r\n }\r\n\r\n /**\r\n * 控制上传 Popover 的显示和隐藏\r\n * @param {boolean} showUpload 是否显示上传的 Popover\r\n */\r\n handleShowUpload(showUpload) {\r\n if (typeof showUpload === \"boolean\") {\r\n this.setState({ showUpload: showUpload });\r\n } else {\r\n this.setState({ showUpload: !this.state.showUpload });\r\n }\r\n }\r\n\r\n /**\r\n * 上传文件\r\n * @param {object} param 文件对象\r\n */\r\n handleUpload({ uid, path }) {\r\n const { fileMap } = this.state;\r\n let { fileList } = this.state;\r\n fileMap[uid] = path;\r\n fileList = fileList.map(item => {\r\n if (item.uid === uid) {\r\n item.thumbUrl = OSS_LINK + path;\r\n }\r\n return item;\r\n });\r\n this.setState({ fileMap, fileList });\r\n }\r\n\r\n /**\r\n * 提交编辑器内容\r\n * 提交功能,交给父组件来实现\r\n * 需要父组件传入 onSubmit\r\n */\r\n handleSubmit() {\r\n const { maxLength } = this.props;\r\n let { value, fileMap, fileList } = this.state;\r\n if (value.length > maxLength) {\r\n message.error(`字数不得超过${maxLength}字`);\r\n return;\r\n }\r\n const files = [];\r\n if (fileList.length) {\r\n fileList.forEach(item => {\r\n if (!fileMap[item.uid]) {\r\n return;\r\n }\r\n files.push(`${OSS_LINK}${fileMap[item.uid]}`);\r\n });\r\n }\r\n if (this.props.beforeSubmit) {\r\n Promise.resolve(this.props.beforeSubmit({ text: value, files })).then(\r\n res => {\r\n if (!(res === false)) {\r\n this.props.onSubmit({ text: value, files }, () => {\r\n this.resetState();\r\n if (this.props.onCommentSuccess) {\r\n this.props.onCommentSuccess();\r\n }\r\n });\r\n }\r\n }\r\n );\r\n } else {\r\n this.props.onSubmit({ text: value, files }, () => {\r\n this.resetState();\r\n if (this.props.onCommentSuccess) {\r\n this.props.onCommentSuccess();\r\n }\r\n });\r\n }\r\n }\r\n\r\n resetState() {\r\n this.setState({\r\n showUpload: false,\r\n value: \"\",\r\n fileList: [],\r\n fileMap: {}\r\n });\r\n }\r\n\r\n render() {\r\n const {\r\n value,\r\n placeholder,\r\n rows,\r\n showEmoji,\r\n showUpload,\r\n closeUploadWhenBlur,\r\n maxUpload,\r\n btnSubmitText,\r\n btnLoading,\r\n btnDisabled,\r\n button,\r\n emojiToolIcon,\r\n imageToolIcon,\r\n maxLength,\r\n autoFocus\r\n } = this.props;\r\n const handleSubmit = this.handleSubmit;\r\n const disabledSubmit =\r\n btnDisabled ||\r\n (!this.props.value && !this.state.value && !this.state.fileList.length);\r\n const inputValue = value || this.state.value;\r\n return (\r\n