1 |
- {"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","intl","get","files","forEach","push","beforeSubmit","Promise","resolve","text","then","res","onSubmit","onCommentSuccess","rows","showEmoji","closeUploadWhenBlur","maxUpload","btnLoading","btnDisabled","button","emojiToolIcon","imageToolIcon","autoFocus","placeholder","btnSubmitText","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;;;;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;A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;AAWpBrC,aAAW;AAXS,CAAtB;;kBAce/B,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 intl from \"react-intl-universal\";\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 this.handleEmojiScroll = this.handleEmojiScroll.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 handleEmojiScroll(e) {\r\n if (!this.emoji) {\r\n return;\r\n }\r\n e.preventDefault();\r\n if (e.deltaY > 0) {\r\n this.emoji.next();\r\n } else if (e.deltaY < 0) {\r\n this.emoji.prev();\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 message.error(intl.get(\"editor.maxLength\", { 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 let placeholder = this.props.placeholder || intl.get(\"editor.placeholder\");\r\n let btnSubmitText =\r\n this.props.btnSubmitText || intl.get(\"editor.SubmitBtn\");\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 <div className=\"comment-editor-container\">\r\n <div\r\n className={classnames({\r\n \"comment-editor-toolbar\": true,\r\n \"comment-editor-toolbar-error\": inputValue.length > maxLength\r\n })}\r\n > \r\n {/* {intl.get(\"editor.alreadyEntered\", {\r\n count: inputValue.length,\r\n maxLength\r\n })} */}\r\n </div>\r\n <div className=\"comment-editor\">\r\n <TextArea\r\n value={inputValue}\r\n onChange={e => this.handleChange(e.target.value)}\r\n rows={rows}\r\n placeholder={placeholder}\r\n autoFocus={autoFocus}\r\n />\r\n\r\n <div className=\"comment-toolbar\">\r\n <div className=\"comment-toolbar-left\">\r\n {showEmoji && (\r\n <Popover\r\n trigger=\"click\"\r\n placement=\"bottomLeft\"\r\n autoAdjustOverflow={false}\r\n content={\r\n <div\r\n style={{ width: 240 }}\r\n onWheel={this.handleEmojiScroll}\r\n >\r\n <Emoji\r\n onClick={this.handleClickEmoji}\r\n ref={node => {\r\n this.emoji = node;\r\n }}\r\n />\r\n </div>\r\n }\r\n overlayClassName=\"comment-emoji-popover\"\r\n >\r\n {emojiToolIcon || (\r\n <Icon type=\"smile-o\" className=\"comment-toolbar-icon\" />\r\n )}\r\n </Popover>\r\n )}\r\n\r\n {showUpload ? (\r\n <Popover\r\n trigger=\"click\"\r\n // TODO: 针对非 react.js,直接使用 click 事件来控制展开或关闭\r\n // visible={this.state.showUpload}\r\n overlayStyle={{ zIndex: 999 }}\r\n onVisibleChange={\r\n closeUploadWhenBlur\r\n ? visible => {\r\n this.handleShowUpload(visible);\r\n }\r\n : null\r\n }\r\n content={\r\n <div\r\n style={{\r\n width: 336, // 一行显示3张\r\n minHeight: 100,\r\n margin: \"0 auto\"\r\n }}\r\n >\r\n <Upload\r\n onChangeFileList={this.handleChangeFileList}\r\n onUpload={this.handleUpload}\r\n maxUpload={maxUpload}\r\n fileList={this.state.fileList}\r\n showError={this.props.showError}\r\n onError={this.props.onError}\r\n />\r\n <div className=\"clearfix\" />\r\n </div>\r\n }\r\n placement=\"bottomLeft\"\r\n title={\r\n <div style={{ margin: \"5px auto\" }}>\r\n <span>\r\n {intl.get(\"editor.uploadTip\")}\r\n {maxUpload >= 2 ? (\r\n <span style={{ color: \"#666\", fontWeight: 400 }}>\r\n (您还能上传\r\n {maxUpload - this.state.fileList.length}\r\n 张图片)\r\n </span>\r\n ) : null}\r\n </span>\r\n {/* 因为是点击别的区域关闭,所以不用右上角的 Icon */}\r\n {/* <Icon\r\n type=\"close\"\r\n onClick={() => this.handleShowUpload(false)}\r\n style={{\r\n float: \"right\",\r\n cursor: \"pointer\",\r\n marginTop: 4\r\n }}\r\n /> */}\r\n </div>\r\n }\r\n >\r\n {imageToolIcon ? (\r\n React.cloneElement(imageToolIcon, {\r\n onClick: () => this.handleShowUpload(true)\r\n })\r\n ) : (\r\n <Icon\r\n type=\"picture\"\r\n className=\"comment-toolbar-icon\"\r\n style={{ marginLeft: 10 }}\r\n onClick={() => this.handleShowUpload(true)}\r\n />\r\n )}\r\n </Popover>\r\n ) : null}\r\n </div>\r\n\r\n <div className=\"comment-toolbar-right\">\r\n {button ? (\r\n React.cloneElement(button, {\r\n onClick: button.props.onClick || handleSubmit\r\n })\r\n ) : (\r\n <Button\r\n onClick={() => this.handleSubmit()}\r\n type=\"primary\"\r\n loading={btnLoading}\r\n disabled={disabledSubmit}\r\n >\r\n {btnSubmitText}\r\n </Button>\r\n )}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n }\r\n}\r\n\r\nEditor.propTypes = {\r\n rows: PropTypes.number,\r\n placeholder: PropTypes.string,\r\n showEmoji: PropTypes.bool,\r\n showUpload: PropTypes.bool,\r\n closeUploadWhenBlur: PropTypes.bool,\r\n maxUpload: PropTypes.number,\r\n value: PropTypes.string,\r\n onChange: PropTypes.func,\r\n onSubmit: PropTypes.func,\r\n beforeSubmit: PropTypes.func,\r\n btnSubmitText: PropTypes.string,\r\n btnLoading: PropTypes.bool,\r\n btnDisabled: PropTypes.bool,\r\n button: PropTypes.node,\r\n emojiToolIcon: PropTypes.node,\r\n imageToolIcon: PropTypes.node,\r\n showError: PropTypes.bool,\r\n onError: PropTypes.func,\r\n maxLength: PropTypes.number\r\n};\r\n\r\nEditor.defaultProps = {\r\n rows: 5,\r\n // placeholder: \"说点什么吧\",\r\n showEmoji: true,\r\n showUpload: true,\r\n closeUploadWhenBlur: false,\r\n maxUpload: 1,\r\n // btnSubmitText: \"发表\",\r\n btnLoading: false,\r\n btnDisabled: false,\r\n showError: true,\r\n maxLength: 5000\r\n};\r\n\r\nexport default Editor;\r\n"]}
|