Browse Source

fix:输入框有初始值时,输入表情会清空问题

zhengyingya 4 years ago
parent
commit
a7e541e56a

+ 1
- 2
lib/components/Editor/index.js View File

@@ -149,8 +149,7 @@ var Editor = function (_React$Component) {
149 149
   }, {
150 150
     key: "handleClickEmoji",
151 151
     value: function handleClickEmoji(emoji) {
152
-      var value = this.state.value;
153
-
152
+      var value = this.props.value || this.state.value;
154 153
       value += "[" + emoji + "]";
155 154
       this.handleChange(value);
156 155
     }

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


+ 2
- 14
lib/index.js View File

@@ -35,13 +35,7 @@ var Index = function (_React$Component) {
35 35
     var _this = _possibleConstructorReturn(this, (Index.__proto__ || Object.getPrototypeOf(Index)).call(this, props));
36 36
 
37 37
     _this.state = {
38
-      fileList: [{
39
-        uid: "1",
40
-        name: "xxx.png",
41
-        status: "done",
42
-        response: "success", // custom error message to show
43
-        url: "//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg"
44
-      }]
38
+      fileList: []
45 39
     };
46 40
     return _this;
47 41
   }
@@ -64,9 +58,6 @@ var Index = function (_React$Component) {
64 58
           autoFocus: true
65 59
         }, this.props.editorProps, {
66 60
           fileList: this.state.fileList,
67
-          onSubmit: function onSubmit() {
68
-            console.log('-----------');
69
-          },
70 61
           handleChangeFileList: function handleChangeFileList(fileList) {
71 62
             _this2.setState({
72 63
               fileList: fileList
@@ -124,10 +115,7 @@ if (process.env.NODE_ENV !== "production") {
124 115
     onCountChange: function onCountChange(c) {
125 116
       console.log(c);
126 117
     },
127
-    editorProps: {
128
-      // emojiPopoverPlacement: "bottom",
129
-      // uploadPopoverPlacement: "top"
130
-    }
118
+    editorProps: {}
131 119
   });
132 120
 }
133 121
 

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

@@ -1 +1 @@
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,qBAAW,CADb;AAEE;AAFF,WAGM,KAAKA,KAAL,CAAWQ,WAHjB;AAIE,oBAAU,KAAKP,KAAL,CAAWC,QAJvB;AAKE,oBACE,oBAAM;AACJO,oBAAQC,GAAR,CAAY,aAAZ;AACD,WARL;AAUE,gCAAsB,wCAAY;AAChC,mBAAKC,QAAL,CAAc;AACZT;AADY,aAAd;AAGD;AAdH;AAPF,OADF;AA0BD;;;;EA5CiBU,gBAAMC,S;;AA+C1B;;;;;;;;;;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;AACAV,YAAQW,IAAR,CAAa,+BAAb;AACD;AACD,MAAI,CAACL,OAAOM,GAAZ,EAAiB;AACf;AACAN,WAAOM,GAAP,GAAa,oCAAb;AACAZ,YAAQW,IAAR,CACE,sDADF;AAGD;;AAEDE,qBAASC,MAAT,CAAgB,8BAAC,KAAD,EAAWR,MAAX,CAAhB,EAAuCS,SAASC,cAAT,CAAwBV,OAAOC,EAA/B,CAAvC;AACA;AACD;;AAEDU,OAAOZ,aAAP,GAAuBA,aAAvB;;AAEA,IAAIa,QAAQC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzCf,gBAAc;AACZE,QAAI,cADQ;AAEZE,UAAM,CAFM;AAGZC,gBAAY,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"]}
1
+{"version":3,"sources":["../src/index.js"],"names":["Index","props","state","fileList","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;AADC,KAAb;AAFiB;AAKlB;;;;6BAEQ;AAAA;;AACP,aACE;AAAC,qBAAD;AAAA;AACE,gCADF;AAEE,8BAFF;AAGE,8BAHF;AAIE;AAJF,WAKM,KAAKF,KALX;AAOE,sCAAC,WAAD;AACE,qBAAW,CADb;AAEE;AAFF,WAGM,KAAKA,KAAL,CAAWG,WAHjB;AAIE,oBAAU,KAAKF,KAAL,CAAWC,QAJvB;AAKE,gCAAsB,wCAAY;AAChC,mBAAKE,QAAL,CAAc;AACZF;AADY,aAAd;AAGD;AATH;AAPF,OADF;AAqBD;;;;EA9BiBG,gBAAMC,S;;AAiC1B;;;;;;;;;;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;AATD,GAAd;AAWD;;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  }\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  });\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,8 +1,8 @@
1 1
 {
2 2
     "name":       "comment",
3
-    "buildDate":  1561187082713,
3
+    "buildDate":  1561545661645,
4 4
     "version":    "1.0.4",
5
-    "numCommits": 152,
6
-    "hash":       "7648f49",
5
+    "numCommits": 156,
6
+    "hash":       "b06e101",
7 7
     "dirty":      true
8 8
 }

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

@@ -69,7 +69,7 @@ class Editor extends React.Component {
69 69
    * @param {string}} emoji emoji 的中文,如 微笑
70 70
    */
71 71
   handleClickEmoji(emoji) {
72
-    let { value } = this.state;
72
+    let value = this.props.value || this.state.value;
73 73
     value += `[${emoji}]`;
74 74
     this.handleChange(value);
75 75
   }

+ 2
- 17
src/index.js View File

@@ -7,16 +7,7 @@ class Index extends React.Component {
7 7
   constructor(props) {
8 8
     super(props);
9 9
     this.state = {
10
-      fileList: [
11
-        {
12
-          uid: "1",
13
-          name: "xxx.png",
14
-          status: "done",
15
-          response: "success", // custom error message to show
16
-          url:
17
-            "//links-comment.oss-cn-beijing.aliyuncs.com/comment/20190617/UCs7aXEjW.jpeg"
18
-        }
19
-      ]
10
+      fileList: []
20 11
     };
21 12
   }
22 13
 
@@ -34,9 +25,6 @@ class Index extends React.Component {
34 25
           autoFocus
35 26
           {...this.props.editorProps}
36 27
           fileList={this.state.fileList}
37
-          onSubmit={() => {
38
-            console.log("-----------");
39
-          }}
40 28
           handleChangeFileList={fileList => {
41 29
             this.setState({
42 30
               fileList
@@ -92,10 +80,7 @@ if (process.env.NODE_ENV !== "production") {
92 80
     onCountChange: c => {
93 81
       console.log(c);
94 82
     },
95
-    editorProps: {
96
-      // emojiPopoverPlacement: "bottom",
97
-      // uploadPopoverPlacement: "top"
98
-    }
83
+    editorProps: {}
99 84
   });
100 85
 }
101 86