@@ -46,69 +46,37 @@ export default class EditorWrapper extends React.Component {
46
46
this . customPlugin = createCustomPlugin ( {
47
47
editor : this ,
48
48
} ) ;
49
-
50
- this . onBeforeInput = this . onBeforeInput . bind ( this ) ;
51
- this . onPasteText = this . onPasteText . bind ( this ) ;
52
49
}
53
50
54
51
componentDidMount ( ) {
55
52
const { connector, initialContent } = this . props ;
56
53
connector . addEditor ( this ) ;
57
- this . setInitialContent ( initialContent ) ;
54
+ if ( initialContent ) {
55
+ let editorState = convertFromHTML ( initialContent ) ;
56
+ editorState = ContentState . createFromBlockArray (
57
+ editorState . contentBlocks ,
58
+ editorState . entityMap ,
59
+ ) ;
60
+ editorState = EditorState . createWithContent ( editorState ) ;
61
+ this . initialContent = editorState . getCurrentContent ( ) ;
62
+ setImmediate ( ( ) => this . setState ( { editor : editorState } ) ) ;
63
+ }
58
64
}
59
65
60
- componentWillReceiveProps ( { connector, id, initialContent } ) {
61
- const { connector : prevConnector , initialContent : prevInitialContent } = this . props ;
66
+ componentWillReceiveProps ( { connector, id } ) {
67
+ const { connector : prevConnector } = this . props ;
62
68
this . id = id ;
63
69
if ( connector !== prevConnector ) {
64
70
if ( prevConnector ) prevConnector . removeEditor ( this ) ;
65
71
if ( connector ) connector . addEditor ( this ) ;
66
72
}
67
- if ( initialContent !== prevInitialContent ) {
68
- this . setInitialContent ( initialContent ) ;
69
- }
70
73
}
71
74
72
75
componentWillUnmount ( ) {
73
76
const { connector } = this . props ;
74
77
connector . removeEditor ( this ) ;
75
78
}
76
79
77
- onBeforeInput ( ) { // eslint-disable-line consistent-return
78
- const { maxLength } = this . props ;
79
- const { editor : editorState } = this . state ;
80
- if ( maxLength !== - 1 && maxLength <= editorState . getCurrentContent ( ) . getPlainText ( '' ) . length ) {
81
- return 'handled' ;
82
- }
83
- }
84
-
85
- onPasteText ( text ) { // eslint-disable-line consistent-return
86
- const { maxLength } = this . props ;
87
- const { editor : editorState } = this . state ;
88
- if ( maxLength !== - 1 && maxLength <= text . length + editorState . getCurrentContent ( ) . getPlainText ( '' ) . length ) {
89
- return 'handled' ;
90
- }
91
- }
92
-
93
- setInitialContent ( content ) {
94
- if ( content ) {
95
- let editorState = convertFromHTML ( content ) ;
96
- if ( editorState . contentBlocks ) {
97
- editorState = ContentState . createFromBlockArray (
98
- editorState . contentBlocks ,
99
- editorState . entityMap ,
100
- ) ;
101
- editorState = EditorState . createWithContent ( editorState ) ;
102
- this . initialContent = editorState . getCurrentContent ( ) ;
103
- setImmediate ( ( ) => this . setState ( { editor : editorState } ) ) ;
104
- }
105
- } else {
106
- let { editor : editorState } = this . state ;
107
- editorState = EditorState . push ( editorState , ContentState . createFromText ( '' ) ) ;
108
- this . setState ( { editor : editorState } ) ;
109
- }
110
- }
111
-
112
80
getHtml ( ) {
113
81
const { editor } = this . state ;
114
82
return editorStateToHTML ( editor . getCurrentContent ( ) ) ;
@@ -130,9 +98,10 @@ export default class EditorWrapper extends React.Component {
130
98
* @param {String } type The new block style
131
99
*/
132
100
applyBlockStyle ( type ) {
133
- let { editor : editorState } = this . state ;
101
+ const { editor } = this . state ;
102
+ let editorState = editor ;
134
103
editorState = RichUtils . toggleBlockType ( editorState , type ) ;
135
- this . setState ( { editor : editorState } ) ; // eslint-disable-line
104
+ this . setState ( { editorState } ) ; // eslint-disable-line
136
105
}
137
106
138
107
/**
@@ -262,16 +231,13 @@ export default class EditorWrapper extends React.Component {
262
231
}
263
232
264
233
render ( ) {
265
- const { connector, theme, placeholder } = this . props ;
234
+ const { connector, theme } = this . props ;
266
235
267
236
const st = this . state ;
268
237
269
238
let containerStyles = style . container ;
270
239
if ( st . editor . getSelection ( ) . getHasFocus ( ) ) {
271
- containerStyles += ` ${ style . focused } is-focused` ;
272
- }
273
- if ( st . editor . getCurrentContent ( ) . hasText ( ) || / < o l > | < u l > / . test ( this . getHtml ( ) ) ) {
274
- containerStyles += ' has-user-input' ;
240
+ containerStyles += ` ${ style . focused } ` ;
275
241
}
276
242
if ( theme . container ) {
277
243
containerStyles += ` ${ theme . container } ` ;
@@ -287,7 +253,6 @@ export default class EditorWrapper extends React.Component {
287
253
tabIndex = { 0 }
288
254
>
289
255
< Editor
290
- placeholder = { placeholder }
291
256
editorState = { st . editor }
292
257
handleKeyCommand = { ( command , state ) => {
293
258
const editorState = RichUtils . handleKeyCommand ( state , command ) ;
@@ -318,8 +283,6 @@ export default class EditorWrapper extends React.Component {
318
283
] }
319
284
ref = { ( node ) => { this . node = node ; } }
320
285
spellCheck
321
- handleBeforeInput = { this . onBeforeInput }
322
- handlePastedText = { this . onPasteText }
323
286
/>
324
287
</ div >
325
288
) ;
@@ -329,17 +292,13 @@ export default class EditorWrapper extends React.Component {
329
292
EditorWrapper . defaultProps = {
330
293
connector : new Connector ( ) ,
331
294
id : null ,
332
- initialContent : '' ,
295
+ initialContent : null ,
333
296
theme : { } ,
334
- placeholder : '' ,
335
- maxLength : - 1 ,
336
297
} ;
337
298
338
299
EditorWrapper . propTypes = {
339
300
connector : PT . instanceOf ( Connector ) ,
340
301
id : PT . string ,
341
302
initialContent : PT . string ,
342
303
theme : PT . shape ( ) ,
343
- placeholder : PT . string ,
344
- maxLength : PT . number ,
345
304
} ;
0 commit comments