{"version":3,"sources":["../../../src/components/CommentInput/index.js"],"names":["CommentInput","props","state","handleSubmit","bind","cb","text","files","value","length","IMAGE_SPLIT","forEach","file","substr","slice","action","commentId","replyId","userId","callback","app","sCreateComment","content","sCreateReply","comment_id","business_user_id","reply_id","childrenWithProps","React","Children","map","cloneElement","child","onSubmit","rows","Component","propTypes","PropTypes","oneOf","defaultProps"],"mappings":";;;;;;;;;;AAAA;;;;AACA;;;;AACA;;AACA;;;;;;;;;;;;IAEMA,Y;;;AACJ,wBAAYC,KAAZ,EAAmB;AAAA;;AAAA,4HACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa,EAAb;AACA,UAAKC,YAAL,GAAoB,MAAKA,YAAL,CAAkBC,IAAlB,OAApB;AAHiB;AAIlB;;AAED;;;;;;;;;uCAK8BC,E,EAAI;AAAA,UAAnBC,IAAmB,QAAnBA,IAAmB;AAAA,UAAbC,KAAa,QAAbA,KAAa;;AAChC,UAAIC,QAAQF,IAAZ;AACA,UAAIC,SAASA,MAAME,MAAnB,EAA2B;AACzBD,iBAASE,qBAAT;AACAH,cAAMI,OAAN,CAAc,gBAAQ;AACpBH,mBAAYI,IAAZ;AACD,SAFD;AAGD;AACD,UAAIJ,MAAMK,MAAN,CAAa,CAAC,CAAd,MAAqB,GAAzB,EAA8B;AAC5BL,gBAAQA,MAAMM,KAAN,CAAY,CAAZ,EAAe,CAAC,CAAhB,CAAR;AACD;;AAV+B,mBAYyB,KAAKb,KAZ9B;AAAA,UAYxBc,MAZwB,UAYxBA,MAZwB;AAAA,UAYhBC,SAZgB,UAYhBA,SAZgB;AAAA,UAYLC,OAZK,UAYLA,OAZK;AAAA,UAYIC,MAZJ,UAYIA,MAZJ;AAAA,UAYYC,QAZZ,UAYYA,QAZZ;;AAahC,UAAIJ,WAAW,SAAf,EAA0B;AACxB,aAAKd,KAAL,CAAWmB,GAAX,CAAeC,cAAf,CACE;AACEC,mBAASd;AADX,SADF,EAIEH,EAJF;AAMD,OAPD,MAOO,IAAIU,WAAW,OAAf,EAAwB;AAC7B,aAAKd,KAAL,CAAWmB,GAAX,CAAeG,YAAf,CACE;AACEC,sBAAYR,SADd;AAEEM,mBAASd,KAFX;AAGEiB,4BAAkBP;AAHpB,SADF,EAME;AAAA,iBAAMC,YAAYA,UAAlB;AAAA,SANF;AAQD,OATM,MASA,IAAIJ,WAAW,cAAf,EAA+B;AACpC,aAAKd,KAAL,CAAWmB,GAAX,CAAeG,YAAf,CACE;AACEC,sBAAYR,SADd;AAEEM,mBAASd,KAFX;AAGEkB,oBAAUT,OAHZ;AAIEQ,4BAAkBP;AAJpB,SADF,EAOE;AAAA,iBAAMC,YAAYA,UAAlB;AAAA,SAPF;AASD;AACF;;;6BAEQ;AAAA;;AACP,UAAMQ,oBAAoBC,gBAAMC,QAAN,CAAeC,GAAf,CAAmB,KAAK7B,KAAL,CAAWqB,OAA9B,EAAuC,iBAAS;AACxE,eAAOM,gBAAMG,YAAN,CAAmBC,KAAnB;AACL;AACA;AACA;AACA;AACAC,oBAAU,OAAK9B;AALV,WAMF6B,MAAM/B,KANJ;AAOL;AACAiC,gBACE,OAAKjC,KAAL,CAAWc,MAAX,KAAsB,SAAtB,GACIiB,MAAM/B,KAAN,CAAYiC,IADhB,GAEIF,MAAM/B,KAAN,CAAYiC,IAAZ,GAAmB;AAXpB,WAAP;AAaD,OAdyB,CAA1B;;AAgBA,aAAO;AAAA;AAAA;AAAMP;AAAN,OAAP;AACD;;;;EAxEwBQ,gB;;AA2E3BnC,aAAaoC,SAAb,GAAyB;AACvB;AACA;AACA;AACArB,UAAQsB,oBAAUC,KAAV,CAAgB,CAAC,SAAD,EAAY,OAAZ,EAAqB,cAArB,CAAhB;AAJe,CAAzB;;AAOAtC,aAAauC,YAAb,GAA4B;AAC1BxB,UAAQ;AADkB,CAA5B;;kBAIe,uBAAQf,YAAR,C","file":"index.js","sourcesContent":["import React, { Component } from \"react\";\r\nimport PropTypes from \"prop-types\";\r\nimport { IMAGE_SPLIT } from \"../../constant\";\r\nimport Comment from \"../../Comment\";\r\n\r\nclass CommentInput extends Component {\r\n constructor(props) {\r\n super(props);\r\n this.state = {};\r\n this.handleSubmit = this.handleSubmit.bind(this);\r\n }\r\n\r\n /**\r\n * 提交评论\r\n * @param {object} { text, files } 需要提交的评论的文本和图片\r\n * @param {function} cb 提交成功后的回掉\r\n */\r\n handleSubmit({ text, files }, cb) {\r\n let value = text;\r\n if (files && files.length) {\r\n value += IMAGE_SPLIT;\r\n files.forEach(file => {\r\n value += `${file},`;\r\n });\r\n }\r\n if (value.substr(-1) === \",\") {\r\n value = value.slice(0, -1);\r\n }\r\n\r\n const { action, commentId, replyId, userId, callback } = this.props;\r\n if (action === \"comment\") {\r\n this.props.app.sCreateComment(\r\n {\r\n content: value\r\n },\r\n cb\r\n );\r\n } else if (action === \"reply\") {\r\n this.props.app.sCreateReply(\r\n {\r\n comment_id: commentId,\r\n content: value,\r\n business_user_id: userId\r\n },\r\n () => callback && callback()\r\n );\r\n } else if (action === \"replyToReply\") {\r\n this.props.app.sCreateReply(\r\n {\r\n comment_id: commentId,\r\n content: value,\r\n reply_id: replyId,\r\n business_user_id: userId\r\n },\r\n () => callback && callback()\r\n );\r\n }\r\n }\r\n\r\n render() {\r\n const childrenWithProps = React.Children.map(this.props.content, child => {\r\n return React.cloneElement(child, {\r\n // 编辑器本身不提交值,但 CommentInput 会提交\r\n // CommentInput 主要是负责评论的业务逻辑,提交评论和回复\r\n // 默认使用 CommentInput 的 onSubmit 来提交评论\r\n // 但也可以使用 Editor 的 props 来覆盖 onSubmit\r\n onSubmit: this.handleSubmit,\r\n ...child.props,\r\n // 如果当前的编辑器不是“评论”,则编辑器高度减小一些\r\n rows:\r\n this.props.action === \"comment\"\r\n ? child.props.rows\r\n : child.props.rows - 1\r\n });\r\n });\r\n\r\n return
{childrenWithProps}
;\r\n }\r\n}\r\n\r\nCommentInput.propTypes = {\r\n // comment 评论\r\n // reply 评论的回复\r\n // replyToReply 回复的回复\r\n action: PropTypes.oneOf([\"comment\", \"reply\", \"replyToReply\"])\r\n};\r\n\r\nCommentInput.defaultProps = {\r\n action: \"comment\"\r\n};\r\n\r\nexport default Comment(CommentInput);\r\n"]}