Преглед на файлове

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

zhengyingya преди 5 години
родител
ревизия
3c8f565a9d
променени са 10 файла, в които са добавени 63 реда и са изтрити 57 реда
  1. 28
    28
      lib/components/Editor/index.js
  2. 1
    1
      lib/components/Editor/index.js.map
  3. 1
    1
      lib/helper.js
  4. 1
    1
      lib/helper.js.map
  5. 3
    0
      lib/index.js
  6. 1
    1
      lib/index.js.map
  7. 3
    3
      lib/version.json
  8. 21
    21
      src/components/Editor/index.js
  9. 1
    1
      src/helper.js
  10. 3
    0
      src/index.js

+ 28
- 28
lib/components/Editor/index.js Целия файл

@@ -219,6 +219,8 @@ var Editor = function (_React$Component) {
219 219
   }, {
220 220
     key: "handleSubmit",
221 221
     value: function handleSubmit() {
222
+      var _this2 = this;
223
+
222 224
       var maxLength = this.props.maxLength;
223 225
       var _state = this.state,
224 226
           value = _state.value,
@@ -243,27 +245,25 @@ var Editor = function (_React$Component) {
243 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 269
     key: "resetState",
@@ -278,7 +278,7 @@ var Editor = function (_React$Component) {
278 278
   }, {
279 279
     key: "render",
280 280
     value: function render() {
281
-      var _this2 = this;
281
+      var _this3 = this;
282 282
 
283 283
       var _props = this.props,
284 284
           value = _props.value,
@@ -321,7 +321,7 @@ var Editor = function (_React$Component) {
321 321
           _react2.default.createElement(TextArea, {
322 322
             value: inputValue,
323 323
             onChange: function onChange(e) {
324
-              return _this2.handleChange(e.target.value);
324
+              return _this3.handleChange(e.target.value);
325 325
             },
326 326
             rows: rows,
327 327
             placeholder: placeholder,
@@ -349,7 +349,7 @@ var Editor = function (_React$Component) {
349 349
                     _react2.default.createElement(_Emoji2.default, {
350 350
                       onClick: this.handleClickEmoji,
351 351
                       ref: function ref(node) {
352
-                        _this2.emoji = node;
352
+                        _this3.emoji = node;
353 353
                       }
354 354
                     })
355 355
                   ),
@@ -368,7 +368,7 @@ var Editor = function (_React$Component) {
368 368
                   autoAdjustOverflow: false,
369 369
                   overlayStyle: { zIndex: 999 },
370 370
                   onVisibleChange: closeUploadWhenBlur ? function (visible) {
371
-                    _this2.handleShowUpload(visible);
371
+                    _this3.handleShowUpload(visible);
372 372
                   } : null,
373 373
                   content: _react2.default.createElement(
374 374
                     "div",
@@ -409,14 +409,14 @@ var Editor = function (_React$Component) {
409 409
                 },
410 410
                 imageToolIcon ? _react2.default.cloneElement(imageToolIcon, {
411 411
                   onClick: function onClick() {
412
-                    return _this2.handleShowUpload(true);
412
+                    return _this3.handleShowUpload(true);
413 413
                   }
414 414
                 }) : _react2.default.createElement(_icon2.default, {
415 415
                   type: "picture",
416 416
                   className: "comment-toolbar-icon",
417 417
                   style: { marginLeft: 10 },
418 418
                   onClick: function onClick() {
419
-                    return _this2.handleShowUpload(true);
419
+                    return _this3.handleShowUpload(true);
420 420
                   }
421 421
                 })
422 422
               ) : null
@@ -430,7 +430,7 @@ var Editor = function (_React$Component) {
430 430
                 _button2.default,
431 431
                 {
432 432
                   onClick: function onClick() {
433
-                    return _this2.handleSubmit();
433
+                    return _this3.handleSubmit();
434 434
                   },
435 435
                   type: "primary",
436 436
                   loading: btnLoading,

+ 1
- 1
lib/components/Editor/index.js.map
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 1
- 1
lib/helper.js Целия файл

@@ -68,7 +68,7 @@ function renderContent(content, onClick) {
68 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 72
   var data = htmlEncode(newContent).replace(_constant.REGEXP, function (a, b) {
73 73
     var src = a.slice(1, -1);
74 74
 

+ 1
- 1
lib/helper.js.map
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 3
- 0
lib/index.js Целия файл

@@ -64,6 +64,9 @@ var Index = function (_React$Component) {
64 64
           autoFocus: true
65 65
         }, this.props.editorProps, {
66 66
           fileList: this.state.fileList,
67
+          onSubmit: function onSubmit() {
68
+            console.log('-----------');
69
+          },
67 70
           handleChangeFileList: function handleChangeFileList(fileList) {
68 71
             _this2.setState({
69 72
               fileList: fileList

+ 1
- 1
lib/index.js.map Целия файл

@@ -1 +1 @@
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,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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ACA","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 Целия файл

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

+ 21
- 21
src/components/Editor/index.js Целия файл

@@ -143,27 +143,27 @@ class Editor extends React.Component {
143 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 169
   resetState() {

+ 1
- 1
src/helper.js Целия файл

@@ -60,7 +60,7 @@ export function renderContent(content, onClick) {
60 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 64
   const data = htmlEncode(newContent)
65 65
     .replace(REGEXP, function(a, b) {
66 66
       const src = a.slice(1, -1);

+ 3
- 0
src/index.js Целия файл

@@ -34,6 +34,9 @@ class Index extends React.Component {
34 34
           autoFocus
35 35
           {...this.props.editorProps}
36 36
           fileList={this.state.fileList}
37
+          onSubmit={() => {
38
+            console.log("-----------");
39
+          }}
37 40
           handleChangeFileList={fileList => {
38 41
             this.setState({
39 42
               fileList