Browse Source

fix:发布回调;fix:渲染文字内部链接匹配

zhengyingya 5 years ago
parent
commit
3c8f565a9d

+ 28
- 28
lib/components/Editor/index.js View File

219
   }, {
219
   }, {
220
     key: "handleSubmit",
220
     key: "handleSubmit",
221
     value: function handleSubmit() {
221
     value: function handleSubmit() {
222
+      var _this2 = this;
223
+
222
       var maxLength = this.props.maxLength;
224
       var maxLength = this.props.maxLength;
223
       var _state = this.state,
225
       var _state = this.state,
224
           value = _state.value,
226
           value = _state.value,
243
           files.push("" + _constant.OSS_LINK + fileMap[item.uid]);
245
           files.push("" + _constant.OSS_LINK + fileMap[item.uid]);
244
         });
246
         });
245
       }
247
       }
246
-      // if (this.props.beforeSubmit) {
247
-      //   Promise.resolve(this.props.beforeSubmit({ text: value, files })).then(
248
-      //     res => {
249
-      //       if (!(res === false)) {
250
-      //         this.props.onSubmit({ text: value, files }, () => {
251
-      //           this.resetState();
252
-      //           if (this.props.onCommentSuccess) {
253
-      //             this.props.onCommentSuccess();
254
-      //           }
255
-      //         });
256
-      //       }
257
-      //     }
258
-      //   );
259
-      // } else {
260
-      //   this.props.onSubmit({ text: value, files }, () => {
261
-      //     this.resetState();
262
-      //     if (this.props.onCommentSuccess) {
263
-      //       this.props.onCommentSuccess();
264
-      //     }
265
-      //   });
266
-      // }
248
+      if (this.props.beforeSubmit) {
249
+        Promise.resolve(this.props.beforeSubmit({ text: value, files: files })).then(function (res) {
250
+          if (!(res === false)) {
251
+            _this2.props.onSubmit({ text: value, files: files }, function () {
252
+              _this2.resetState();
253
+              if (_this2.props.onCommentSuccess) {
254
+                _this2.props.onCommentSuccess();
255
+              }
256
+            });
257
+          }
258
+        });
259
+      } else {
260
+        this.props.onSubmit({ text: value, files: files }, function () {
261
+          _this2.resetState();
262
+          if (_this2.props.onCommentSuccess) {
263
+            _this2.props.onCommentSuccess();
264
+          }
265
+        });
266
+      }
267
     }
267
     }
268
   }, {
268
   }, {
269
     key: "resetState",
269
     key: "resetState",
278
   }, {
278
   }, {
279
     key: "render",
279
     key: "render",
280
     value: function render() {
280
     value: function render() {
281
-      var _this2 = this;
281
+      var _this3 = this;
282
 
282
 
283
       var _props = this.props,
283
       var _props = this.props,
284
           value = _props.value,
284
           value = _props.value,
321
           _react2.default.createElement(TextArea, {
321
           _react2.default.createElement(TextArea, {
322
             value: inputValue,
322
             value: inputValue,
323
             onChange: function onChange(e) {
323
             onChange: function onChange(e) {
324
-              return _this2.handleChange(e.target.value);
324
+              return _this3.handleChange(e.target.value);
325
             },
325
             },
326
             rows: rows,
326
             rows: rows,
327
             placeholder: placeholder,
327
             placeholder: placeholder,
349
                     _react2.default.createElement(_Emoji2.default, {
349
                     _react2.default.createElement(_Emoji2.default, {
350
                       onClick: this.handleClickEmoji,
350
                       onClick: this.handleClickEmoji,
351
                       ref: function ref(node) {
351
                       ref: function ref(node) {
352
-                        _this2.emoji = node;
352
+                        _this3.emoji = node;
353
                       }
353
                       }
354
                     })
354
                     })
355
                   ),
355
                   ),
368
                   autoAdjustOverflow: false,
368
                   autoAdjustOverflow: false,
369
                   overlayStyle: { zIndex: 999 },
369
                   overlayStyle: { zIndex: 999 },
370
                   onVisibleChange: closeUploadWhenBlur ? function (visible) {
370
                   onVisibleChange: closeUploadWhenBlur ? function (visible) {
371
-                    _this2.handleShowUpload(visible);
371
+                    _this3.handleShowUpload(visible);
372
                   } : null,
372
                   } : null,
373
                   content: _react2.default.createElement(
373
                   content: _react2.default.createElement(
374
                     "div",
374
                     "div",
409
                 },
409
                 },
410
                 imageToolIcon ? _react2.default.cloneElement(imageToolIcon, {
410
                 imageToolIcon ? _react2.default.cloneElement(imageToolIcon, {
411
                   onClick: function onClick() {
411
                   onClick: function onClick() {
412
-                    return _this2.handleShowUpload(true);
412
+                    return _this3.handleShowUpload(true);
413
                   }
413
                   }
414
                 }) : _react2.default.createElement(_icon2.default, {
414
                 }) : _react2.default.createElement(_icon2.default, {
415
                   type: "picture",
415
                   type: "picture",
416
                   className: "comment-toolbar-icon",
416
                   className: "comment-toolbar-icon",
417
                   style: { marginLeft: 10 },
417
                   style: { marginLeft: 10 },
418
                   onClick: function onClick() {
418
                   onClick: function onClick() {
419
-                    return _this2.handleShowUpload(true);
419
+                    return _this3.handleShowUpload(true);
420
                   }
420
                   }
421
                 })
421
                 })
422
               ) : null
422
               ) : null
430
                 _button2.default,
430
                 _button2.default,
431
                 {
431
                 {
432
                   onClick: function onClick() {
432
                   onClick: function onClick() {
433
-                    return _this2.handleSubmit();
433
+                    return _this3.handleSubmit();
434
                   },
434
                   },
435
                   type: "primary",
435
                   type: "primary",
436
                   loading: btnLoading,
436
                   loading: btnLoading,

+ 1
- 1
lib/components/Editor/index.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
lib/helper.js View File

68
     newContent = newContent.join("");
68
     newContent = newContent.join("");
69
   }
69
   }
70
   // 不包含在标签内的链接
70
   // 不包含在标签内的链接
71
-  var innerUrl = /((http(s)?:)?\/\/)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)(?![^<>]*>|[^"]*?<\/a)/g;
71
+  var innerUrl = /((http(s)?:)?\/\/)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[com|net|org|cn|edu|top|gov]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)(?![^<>]*>|[^"]*?<\/a)/g;
72
   var data = htmlEncode(newContent).replace(_constant.REGEXP, function (a, b) {
72
   var data = htmlEncode(newContent).replace(_constant.REGEXP, function (a, b) {
73
     var src = a.slice(1, -1);
73
     var src = a.slice(1, -1);
74
 
74
 

+ 1
- 1
lib/helper.js.map
File diff suppressed because it is too large
View File


+ 3
- 0
lib/index.js View File

64
           autoFocus: true
64
           autoFocus: true
65
         }, this.props.editorProps, {
65
         }, this.props.editorProps, {
66
           fileList: this.state.fileList,
66
           fileList: this.state.fileList,
67
+          onSubmit: function onSubmit() {
68
+            console.log('-----------');
69
+          },
67
           handleChangeFileList: function handleChangeFileList(fileList) {
70
           handleChangeFileList: function handleChangeFileList(fileList) {
68
             _this2.setState({
71
             _this2.setState({
69
               fileList: fileList
72
               fileList: fileList

+ 1
- 1
lib/index.js.map View File

1
-{"version":3,"sources":["../src/index.js"],"names":["Index","props","state","fileList","uid","name","status","response","url","editorProps","setState","React","Component","renderComment","config","id","Error","type","businessId","console","warn","API","ReactDOM","render","document","getElementById","window","process","env","NODE_ENV","businessUserId","userId","onCountChange","log","c"],"mappings":";;;;;;AAAA;;;;AACA;;;;AACA;;;;;;;;;;;;AACA;;IAEMA,K;;;AACJ,iBAAYC,KAAZ,EAAmB;AAAA;;AAAA,8GACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,gBAAU,CACR;AACEC,aAAK,GADP;AAEEC,cAAM,SAFR;AAGEC,gBAAQ,MAHV;AAIEC,kBAAU,SAJZ,EAIuB;AACrBC,aACE;AANJ,OADQ;AADC,KAAb;AAFiB;AAclB;;;;6BAEQ;AAAA;;AACP,aACE;AAAC,qBAAD;AAAA;AACE,gCADF;AAEE,8BAFF;AAGE,8BAHF;AAIE;AAJF,WAKM,KAAKP,KALX;AAOE,sCAAC,WAAD;AACE,qBAAW,CADb;AAEE;AAFF,WAGM,KAAKA,KAAL,CAAWQ,WAHjB;AAIE,oBAAU,KAAKP,KAAL,CAAWC,QAJvB;AAKE,gCAAsB,wCAAY;AAChC,mBAAKO,QAAL,CAAc;AACZP;AADY,aAAd;AAGD;AATH;AAPF,OADF;AAqBD;;;;EAvCiBQ,gBAAMC,S;;AA0C1B;;;;;;;;;;AAQA,SAASC,aAAT,CAAuBC,MAAvB,EAA+B;AAC7B,MAAI,CAACA,OAAOC,EAAZ,EAAgB;AACd,UAAM,IAAIC,KAAJ,CAAU,gBAAV,CAAN;AACD;AACD,MAAI,CAACF,OAAOG,IAAZ,EAAkB;AAChB,UAAM,IAAID,KAAJ,CAAU,kBAAV,CAAN;AACD;AACD,MAAI,CAACF,OAAOI,UAAZ,EAAwB;AACtB;AACAJ,WAAOI,UAAP,GAAoB,MAApB;AACAC,YAAQC,IAAR,CAAa,+BAAb;AACD;AACD,MAAI,CAACN,OAAOO,GAAZ,EAAiB;AACf;AACAP,WAAOO,GAAP,GAAa,oCAAb;AACAF,YAAQC,IAAR,CACE,sDADF;AAGD;;AAEDE,qBAASC,MAAT,CAAgB,8BAAC,KAAD,EAAWT,MAAX,CAAhB,EAAuCU,SAASC,cAAT,CAAwBX,OAAOC,EAA/B,CAAvC;AACA;AACD;;AAEDW,OAAOb,aAAP,GAAuBA,aAAvB;;AAEA,IAAIc,QAAQC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzChB,gBAAc;AACZE,QAAI,cADQ;AAEZE,UAAM,CAFM;AAGZC,gBAAY,MAHA;AAIZY,oBAAgB,CAJJ;AAKZC,YAAQ,KALI;AAMZC,mBAAe,0BAAK;AAClBb,cAAQc,GAAR,CAAYC,CAAZ;AACD,KARW;AASZzB,iBAAa;AACX;AACA;AAFW;AATD,GAAd;AAcD;;AAED;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["import React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport App, { Editor } from \"./App\";\n// import registerServiceWorker from \"./registerServiceWorker\";\n\nclass Index extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      fileList: [\n        {\n          uid: \"1\",\n          name: \"xxx.png\",\n          status: \"done\",\n          response: \"success\", // custom error message to show\n          url:\n            \"//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg\"\n        }\n      ]\n    };\n  }\n\n  render() {\n    return (\n      <App\n        showAlertComment\n        showAlertReply\n        showAlertFavor\n        showError\n        {...this.props}\n      >\n        <Editor\n          maxUpload={9}\n          autoFocus\n          {...this.props.editorProps}\n          fileList={this.state.fileList}\n          handleChangeFileList={fileList => {\n            this.setState({\n              fileList\n            });\n          }}\n        />\n      </App>\n    );\n  }\n}\n\n/**\n * 渲染评论组件\n * @param {object} config 编辑器配置\n *  - {string} id 渲染评论的DOM的 ID\n *  - {number} type 评论的 type\n *  - {string} businessId 评论的 businessId\n *  - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1\n */\nfunction renderComment(config) {\n  if (!config.id) {\n    throw new Error(\"id is required\");\n  }\n  if (!config.type) {\n    throw new Error(\"type is required\");\n  }\n  if (!config.businessId) {\n    // throw new Error(\"businessId is required\");\n    config.businessId = \"test\";\n    console.warn(\"没有传入 businessId 参数,默认使用: test\");\n  }\n  if (!config.API) {\n    // throw new Error(\"API is required\");\n    config.API = \"http://api.links123.net/comment/v1\";\n    console.warn(\n      \"没有传入 API 参数,默认使用: http://api.links123.net/comment/v1\"\n    );\n  }\n\n  ReactDOM.render(<Index {...config} />, document.getElementById(config.id));\n  // registerServiceWorker();\n}\n\nwindow.renderComment = renderComment;\n\nif (process.env.NODE_ENV !== \"production\") {\n  renderComment({\n    id: \"root-comment\",\n    type: 1,\n    businessId: \"test\",\n    businessUserId: 4,\n    userId: 71299,\n    onCountChange: c => {\n      console.log(c);\n    },\n    editorProps: {\n      // emojiPopoverPlacement: \"bottom\",\n      // uploadPopoverPlacement: \"top\"\n    }\n  });\n}\n\n// renderComment({\n//   id: \"root-comment\",\n//   type: 1,\n//   businessId: \"test\",\n//   API: 'http://api.links123.net/comment/v1',\n// });\n"]}
1
+{"version":3,"sources":["../src/index.js"],"names":["Index","props","state","fileList","uid","name","status","response","url","editorProps","console","log","setState","React","Component","renderComment","config","id","Error","type","businessId","warn","API","ReactDOM","render","document","getElementById","window","process","env","NODE_ENV","businessUserId","userId","onCountChange","c"],"mappings":";;;;;;AAAA;;;;AACA;;;;AACA;;;;;;;;;;;;AACA;;IAEMA,K;;;AACJ,iBAAYC,KAAZ,EAAmB;AAAA;;AAAA,8GACXA,KADW;;AAEjB,UAAKC,KAAL,GAAa;AACXC,gBAAU,CACR;AACEC,aAAK,GADP;AAEEC,cAAM,SAFR;AAGEC,gBAAQ,MAHV;AAIEC,kBAAU,SAJZ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BAAY,MAHA;AAIZW,oBAAgB,CAJJ;AAKZC,YAAQ,KALI;AAMZC,mBAAe,0BAAK;AAClBvB,cAAQC,GAAR,CAAYuB,CAAZ;AACD,KARW;AASZzB,iBAAa;AACX;AACA;AAFW;AATD,GAAd;AAcD;;AAED;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["import React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport App, { Editor } from \"./App\";\n// import registerServiceWorker from \"./registerServiceWorker\";\n\nclass Index extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      fileList: [\n        {\n          uid: \"1\",\n          name: \"xxx.png\",\n          status: \"done\",\n          response: \"success\", // custom error message to show\n          url:\n            \"//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg\"\n        }\n      ]\n    };\n  }\n\n  render() {\n    return (\n      <App\n        showAlertComment\n        showAlertReply\n        showAlertFavor\n        showError\n        {...this.props}\n      >\n        <Editor\n          maxUpload={9}\n          autoFocus\n          {...this.props.editorProps}\n          fileList={this.state.fileList}\n          onSubmit={\n            () => {\n              console.log('-----------')\n            }\n          }\n          handleChangeFileList={fileList => {\n            this.setState({\n              fileList\n            });\n          }}\n        />\n      </App>\n    );\n  }\n}\n\n/**\n * 渲染评论组件\n * @param {object} config 编辑器配置\n *  - {string} id 渲染评论的DOM的 ID\n *  - {number} type 评论的 type\n *  - {string} businessId 评论的 businessId\n *  - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1\n */\nfunction renderComment(config) {\n  if (!config.id) {\n    throw new Error(\"id is required\");\n  }\n  if (!config.type) {\n    throw new Error(\"type is required\");\n  }\n  if (!config.businessId) {\n    // throw new Error(\"businessId is required\");\n    config.businessId = \"test\";\n    console.warn(\"没有传入 businessId 参数,默认使用: test\");\n  }\n  if (!config.API) {\n    // throw new Error(\"API is required\");\n    config.API = \"http://api.links123.net/comment/v1\";\n    console.warn(\n      \"没有传入 API 参数,默认使用: http://api.links123.net/comment/v1\"\n    );\n  }\n\n  ReactDOM.render(<Index {...config} />, document.getElementById(config.id));\n  // registerServiceWorker();\n}\n\nwindow.renderComment = renderComment;\n\nif (process.env.NODE_ENV !== \"production\") {\n  renderComment({\n    id: \"root-comment\",\n    type: 1,\n    businessId: \"test\",\n    businessUserId: 4,\n    userId: 71299,\n    onCountChange: c => {\n      console.log(c);\n    },\n    editorProps: {\n      // emojiPopoverPlacement: \"bottom\",\n      // uploadPopoverPlacement: \"top\"\n    }\n  });\n}\n\n// renderComment({\n//   id: \"root-comment\",\n//   type: 1,\n//   businessId: \"test\",\n//   API: 'http://api.links123.net/comment/v1',\n// });\n"]}

+ 3
- 3
lib/version.json View File

1
 {
1
 {
2
     "name":       "comment",
2
     "name":       "comment",
3
-    "buildDate":  1561169930396,
3
+    "buildDate":  1561187082713,
4
     "version":    "1.0.4",
4
     "version":    "1.0.4",
5
-    "numCommits": 151,
6
-    "hash":       "1d304ca",
5
+    "numCommits": 152,
6
+    "hash":       "7648f49",
7
     "dirty":      true
7
     "dirty":      true
8
 }
8
 }

+ 21
- 21
src/components/Editor/index.js View File

143
         files.push(`${OSS_LINK}${fileMap[item.uid]}`);
143
         files.push(`${OSS_LINK}${fileMap[item.uid]}`);
144
       });
144
       });
145
     }
145
     }
146
-    // if (this.props.beforeSubmit) {
147
-    //   Promise.resolve(this.props.beforeSubmit({ text: value, files })).then(
148
-    //     res => {
149
-    //       if (!(res === false)) {
150
-    //         this.props.onSubmit({ text: value, files }, () => {
151
-    //           this.resetState();
152
-    //           if (this.props.onCommentSuccess) {
153
-    //             this.props.onCommentSuccess();
154
-    //           }
155
-    //         });
156
-    //       }
157
-    //     }
158
-    //   );
159
-    // } else {
160
-    //   this.props.onSubmit({ text: value, files }, () => {
161
-    //     this.resetState();
162
-    //     if (this.props.onCommentSuccess) {
163
-    //       this.props.onCommentSuccess();
164
-    //     }
165
-    //   });
166
-    // }
146
+    if (this.props.beforeSubmit) {
147
+      Promise.resolve(this.props.beforeSubmit({ text: value, files })).then(
148
+        res => {
149
+          if (!(res === false)) {
150
+            this.props.onSubmit({ text: value, files }, () => {
151
+              this.resetState();
152
+              if (this.props.onCommentSuccess) {
153
+                this.props.onCommentSuccess();
154
+              }
155
+            });
156
+          }
157
+        }
158
+      );
159
+    } else {
160
+      this.props.onSubmit({ text: value, files }, () => {
161
+        this.resetState();
162
+        if (this.props.onCommentSuccess) {
163
+          this.props.onCommentSuccess();
164
+        }
165
+      });
166
+    }
167
   }
167
   }
168
 
168
 
169
   resetState() {
169
   resetState() {

+ 1
- 1
src/helper.js View File

60
     newContent = newContent.join("");
60
     newContent = newContent.join("");
61
   }
61
   }
62
   // 不包含在标签内的链接
62
   // 不包含在标签内的链接
63
-  const innerUrl = /((http(s)?:)?\/\/)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)(?![^<>]*>|[^"]*?<\/a)/g;
63
+  const innerUrl = /((http(s)?:)?\/\/)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[com|net|org|cn|edu|top|gov]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)(?![^<>]*>|[^"]*?<\/a)/g;
64
   const data = htmlEncode(newContent)
64
   const data = htmlEncode(newContent)
65
     .replace(REGEXP, function(a, b) {
65
     .replace(REGEXP, function(a, b) {
66
       const src = a.slice(1, -1);
66
       const src = a.slice(1, -1);

+ 3
- 0
src/index.js View File

34
           autoFocus
34
           autoFocus
35
           {...this.props.editorProps}
35
           {...this.props.editorProps}
36
           fileList={this.state.fileList}
36
           fileList={this.state.fileList}
37
+          onSubmit={() => {
38
+            console.log("-----------");
39
+          }}
37
           handleChangeFileList={fileList => {
40
           handleChangeFileList={fileList => {
38
             this.setState({
41
             this.setState({
39
               fileList
42
               fileList