Browse Source

feature: 编辑器内部值支持预处理函数preRenderValue

Roxas 4 years ago
parent
commit
38edbfc2c7

+ 8
- 3
lib/App.js View File

@@ -766,7 +766,8 @@ var App = function (_Component) {
766 766
           commentId: this.state.commentId,
767 767
           userId: this.state.content.user_id,
768 768
           content: this.state.content,
769
-          handleClose: this.handleClose
769
+          handleClose: this.handleClose,
770
+          preRenderValue: this.props.preRenderValue
770 771
         })
771 772
       );
772 773
     }
@@ -797,7 +798,8 @@ App.propTypes = {
797 798
   onUpdateComment: _propTypes2.default.func,
798 799
   locales: _propTypes2.default.string, //  传入的语言环境, en-US/zh-CN
799 800
   onCountChange: _propTypes2.default.func, // 评论数量变更时的回调
800
-  onCommentFail: _propTypes2.default.func // 评论失败时的回调
801
+  onCommentFail: _propTypes2.default.func, // 评论失败时的回调
802
+  preRenderValue: _propTypes2.default.func // 编辑器渲染前对值需要做的工作
801 803
 };
802 804
 
803 805
 App.defaultProps = {
@@ -820,7 +822,10 @@ App.defaultProps = {
820 822
   onUpdateComment: function onUpdateComment() {},
821 823
   onBeforeUpdateComment: function onBeforeUpdateComment() {},
822 824
   onCountChange: function onCountChange() {},
823
-  onCommentFail: function onCommentFail() {}
825
+  onCommentFail: function onCommentFail() {},
826
+  preRenderValue: function preRenderValue(v) {
827
+    return v;
828
+  }
824 829
 };
825 830
 
826 831
 exports.Editor = _Editor2.default;

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


+ 1
- 1
lib/components/EditComment/EditComment.js View File

@@ -193,7 +193,7 @@ var EditComment = function (_React$Component) {
193 193
             commentId: this.props.commentId,
194 194
             userId: this.props.content.user_id,
195 195
             fileList: this.state.fileList,
196
-            value: this.state.value,
196
+            value: this.props.preRenderValue && this.props.preRenderValue(this.state.value),
197 197
             onChange: function onChange(value) {
198 198
               _this2.setState({
199 199
                 value: value

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


+ 2
- 2
lib/components/Editor/Upload.js View File

@@ -232,8 +232,8 @@ var App = function (_React$Component) {
232 232
             onClick: _this3.handleCloseClick.bind(_this3, index),
233 233
             key: file.uid,
234 234
             style: {
235
-              left: index % 3 * 112 + 110 + "px",
236
-              top: Math.floor(index / 3) * 112 + 26 + "px"
235
+              left: index % 3 * 112 + 98 + "px",
236
+              top: Math.floor(index / 3) * 112 + 16 + "px"
237 237
             }
238 238
           });
239 239
         }),

+ 3
- 0
lib/index.js View File

@@ -194,6 +194,9 @@ if (process.env.NODE_ENV !== "production") {
194 194
     sendMessage: function sendMessage(id) {
195 195
       console.log("sendMessage", id);
196 196
     },
197
+    preRenderValue: function preRenderValue(value) {
198
+      return "" + value;
199
+    },
197 200
     editorProps: {
198 201
       onCommentSuccess: function onCommentSuccess(data) {
199 202
         console.log(data);

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


+ 4
- 4
lib/version.json View File

@@ -1,8 +1,8 @@
1 1
 {
2 2
     "name":       "comment",
3
-    "buildDate":  1574306910894,
3
+    "buildDate":  1577536315907,
4 4
     "version":    "1.0.4",
5
-    "numCommits": 195,
6
-    "hash":       "db0a99c",
7
-    "dirty":      false
5
+    "numCommits": 197,
6
+    "hash":       "92e9ffb",
7
+    "dirty":      true
8 8
 }

+ 5
- 2
src/App.js View File

@@ -617,6 +617,7 @@ class App extends Component {
617 617
               userId={this.state.content.user_id}
618 618
               content={this.state.content}
619 619
               handleClose={this.handleClose}
620
+              preRenderValue={this.props.preRenderValue}
620 621
             />
621 622
           )}
622 623
         </CommentContext.Provider>
@@ -647,7 +648,8 @@ App.propTypes = {
647 648
   onUpdateComment: PropTypes.func,
648 649
   locales: PropTypes.string, //  传入的语言环境, en-US/zh-CN
649 650
   onCountChange: PropTypes.func, // 评论数量变更时的回调
650
-  onCommentFail: PropTypes.func // 评论失败时的回调
651
+  onCommentFail: PropTypes.func, // 评论失败时的回调
652
+  preRenderValue: PropTypes.func // 编辑器渲染前对值需要做的工作
651 653
 };
652 654
 
653 655
 App.defaultProps = {
@@ -673,7 +675,8 @@ App.defaultProps = {
673 675
   onUpdateComment: () => {},
674 676
   onBeforeUpdateComment: () => {},
675 677
   onCountChange: () => {},
676
-  onCommentFail: () => {}
678
+  onCommentFail: () => {},
679
+  preRenderValue: v => v
677 680
 };
678 681
 
679 682
 export { Editor, RenderText };

+ 4
- 1
src/components/EditComment/EditComment.js View File

@@ -111,7 +111,10 @@ class EditComment extends React.Component {
111 111
               commentId={this.props.commentId}
112 112
               userId={this.props.content.user_id}
113 113
               fileList={this.state.fileList}
114
-              value={this.state.value}
114
+              value={
115
+                this.props.preRenderValue &&
116
+                this.props.preRenderValue(this.state.value)
117
+              }
115 118
               onChange={value => {
116 119
                 this.setState({
117 120
                   value

+ 3
- 0
src/index.js View File

@@ -159,6 +159,9 @@ if (process.env.NODE_ENV !== "production") {
159 159
     sendMessage: id => {
160 160
       console.log("sendMessage", id);
161 161
     },
162
+    preRenderValue: value => {
163
+      return `${value}`;
164
+    },
162 165
     editorProps: {
163 166
       onCommentSuccess: data => {
164 167
         console.log(data);