通用评论

index.js.map 4.0KB

1
  1. {"version":3,"sources":["../../../src/components/CommentInput/index.js"],"names":["CommentInput","props","state","handleSubmit","bind","value","cb","action","commentId","replyId","callback","app","sCreateComment","content","sCreateReply","comment_id","reply_id","childrenWithProps","React","Children","map","cloneElement","child","onSubmit","rows","Component","propTypes","PropTypes","oneOf","defaultProps"],"mappings":";;;;;;;;;;AAAA;;;;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;;;;;;;;;iCAKaC,K,EAAOC,E,EAAI;AAAA,mBAC2B,KAAKL,KADhC;AAAA,UACdM,MADc,UACdA,MADc;AAAA,UACNC,SADM,UACNA,SADM;AAAA,UACKC,OADL,UACKA,OADL;AAAA,UACcC,QADd,UACcA,QADd;;AAEtB,UAAIH,WAAW,SAAf,EAA0B;AACxB,aAAKN,KAAL,CAAWU,GAAX,CAAeC,cAAf,CACE;AACEC,mBAASR;AADX,SADF,EAIEC,EAJF;AAMD,OAPD,MAOO,IAAIC,WAAW,OAAf,EAAwB;AAC7B,aAAKN,KAAL,CAAWU,GAAX,CAAeG,YAAf,CACE;AACEC,sBAAYP,SADd;AAEEK,mBAASR;AAFX,SADF,EAKE;AAAA,iBAAMK,YAAYA,UAAlB;AAAA,SALF;AAOD,OARM,MAQA,IAAIH,WAAW,cAAf,EAA+B;AACpC,aAAKN,KAAL,CAAWU,GAAX,CAAeG,YAAf,CACE;AACEC,sBAAYP,SADd;AAEEK,mBAASR,KAFX;AAGEW,oBAAUP;AAHZ,SADF,EAME;AAAA,iBAAMC,YAAYA,UAAlB;AAAA,SANF;AAQD;AACF;;;6BAEQ;AAAA;;AACP,UAAMO,oBAAoBC,gBAAMC,QAAN,CAAeC,GAAf,CAAmB,KAAKnB,KAAL,CAAWY,OAA9B,EAAuC,iBAAS;AACxE,eAAOK,gBAAMG,YAAN,CAAmBC,KAAnB;AACL;AACA;AACA;AACA;AACAC,oBAAU,OAAKpB;AALV,WAMFmB,MAAMrB,KANJ;AAOL;AACAuB,gBACE,OAAKvB,KAAL,CAAWM,MAAX,KAAsB,SAAtB,GACIe,MAAMrB,KAAN,CAAYuB,IADhB,GAEIF,MAAMrB,KAAN,CAAYuB,IAAZ,GAAmB;AAXpB,WAAP;AAaD,OAdyB,CAA1B;;AAgBA,aAAO;AAAA;AAAA;AAAMP;AAAN,OAAP;AACD;;;;EA3DwBQ,gB;;AA8D3BzB,aAAa0B,SAAb,GAAyB;AACvB;AACA;AACA;AACAnB,UAAQoB,oBAAUC,KAAV,CAAgB,CAAC,SAAD,EAAY,OAAZ,EAAqB,cAArB,CAAhB;AAJe,CAAzB;;AAOA5B,aAAa6B,YAAb,GAA4B;AAC1BtB,UAAQ;AADkB,CAA5B;;kBAIe,uBAAQP,YAAR,C","file":"index.js","sourcesContent":["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\nimport Comment from '../../Comment';\n\nclass CommentInput extends Component {\n constructor(props) {\n super(props);\n this.state = {};\n this.handleSubmit = this.handleSubmit.bind(this);\n }\n\n /**\n * 提交评论\n * @param {string} value 需要提交的评论的值\n * @param {function} cb 提交成功后的回掉\n */\n handleSubmit(value, cb) {\n const { action, commentId, replyId, callback } = this.props;\n if (action === 'comment') {\n this.props.app.sCreateComment(\n {\n content: value,\n },\n cb\n );\n } else if (action === 'reply') {\n this.props.app.sCreateReply(\n {\n comment_id: commentId,\n content: value,\n },\n () => callback && callback()\n );\n } else if (action === 'replyToReply') {\n this.props.app.sCreateReply(\n {\n comment_id: commentId,\n content: value,\n reply_id: replyId,\n },\n () => callback && callback()\n );\n }\n }\n\n render() {\n const childrenWithProps = React.Children.map(this.props.content, child => {\n return React.cloneElement(child, {\n // 编辑器本身不提交值,但 CommentInput 会提交\n // CommentInput 主要是负责评论的业务逻辑,提交评论和回复\n // 默认使用 CommentInput 的 onSubmit 来提交评论\n // 但也可以使用 Editor 的 props 来覆盖 onSubmit\n onSubmit: this.handleSubmit,\n ...child.props,\n // 如果当前的编辑器不是“评论”,则编辑器高度减小一些\n rows:\n this.props.action === 'comment'\n ? child.props.rows\n : child.props.rows - 1,\n });\n });\n\n return <div>{childrenWithProps}</div>;\n }\n}\n\nCommentInput.propTypes = {\n // comment 评论\n // reply 评论的回复\n // replyToReply 回复的回复\n action: PropTypes.oneOf(['comment', 'reply', 'replyToReply']),\n};\n\nCommentInput.defaultProps = {\n action: 'comment',\n};\n\nexport default Comment(CommentInput);\n"]}