1
- var React = require ( 'react' ) ;
2
- var DOM = React . DOM ;
3
- var isEqual = require ( 'lodash/lang/isEqual' ) ;
4
- var uuid = require ( '../helpers/uuid' ) ;
5
- var uc_first = require ( '../helpers/uc_first' ) ;
1
+ import React , { DOM } from 'react' ;
2
+ import isEqual from 'lodash/lang/isEqual' ;
3
+ import uuid from '../helpers/uuid' ;
4
+ import ucFirst from '../helpers/ucFirst' ;
6
5
7
6
// Include all of the Native DOM and custom events from:
8
7
// https://github.com/tinymce/tinymce/blob/master/tools/docs/tinymce.Editor.js#L5-L12
9
- var EVENTS = [
8
+ const EVENTS = [
10
9
'focusin' , 'focusout' , 'click' , 'dblclick' , 'mousedown' , 'mouseup' ,
11
10
'mousemove' , 'mouseover' , 'beforepaste' , 'paste' , 'cut' , 'copy' ,
12
11
'selectionchange' , 'mouseout' , 'mouseenter' , 'mouseleave' , 'keydown' ,
@@ -24,101 +23,99 @@ var EVENTS = [
24
23
// Note: because the capitalization of the events is weird, we're going to get
25
24
// some inconsistently-named handlers, for example compare:
26
25
// 'onMouseleave' and 'onNodeChange'
27
- var HANDLER_NAMES = EVENTS . map ( function ( event ) {
28
- return 'on' + uc_first ( event ) ;
26
+ const HANDLER_NAMES = EVENTS . map ( ( event ) => {
27
+ return 'on' + ucFirst ( event ) ;
29
28
} ) ;
30
29
31
- var TinyMCE = React . createClass ( {
30
+ const TinyMCE = React . createClass ( {
32
31
displayName : 'TinyMCE' ,
33
32
34
33
propTypes : {
35
34
config : React . PropTypes . object ,
36
- content : React . PropTypes . string ,
35
+ content : React . PropTypes . string
37
36
} ,
38
37
39
- getDefaultProps : function ( ) {
38
+ getDefaultProps ( ) {
40
39
return {
41
40
config : { } ,
42
41
content : ''
43
42
} ;
44
43
} ,
45
44
46
- componentWillMount : function ( ) {
45
+ componentWillMount ( ) {
47
46
this . id = this . id || uuid ( ) ;
48
47
} ,
49
48
50
- componentDidMount : function ( ) {
49
+ componentDidMount ( ) {
51
50
this . _init ( this . props . config ) ;
52
51
} ,
53
52
54
- componentWillUnmount : function ( ) {
53
+ componentWillUnmount ( ) {
55
54
this . _remove ( ) ;
56
55
} ,
57
56
58
- componentWillReceiveProps : function ( nextProps ) {
57
+ componentWillReceiveProps ( nextProps ) {
59
58
if ( ! isEqual ( this . props . config , nextProps . config ) ) {
60
59
this . _init ( nextProps . config , nextProps . content ) ;
61
60
}
62
61
} ,
63
62
64
- shouldComponentUpdate : function ( nextProps , nextState ) {
63
+ shouldComponentUpdate ( nextProps ) {
65
64
return (
66
65
! isEqual ( this . props . content , nextProps . content ) ||
67
66
! isEqual ( this . props . config , nextProps . config )
68
67
) ;
69
68
} ,
70
69
71
- _init : function ( config , content ) {
70
+ render ( ) {
71
+ return DOM . textarea ( {
72
+ id : this . id ,
73
+ defaultValue : this . props . content
74
+ } ) ;
75
+ } ,
76
+
77
+ _init ( config , content ) {
72
78
if ( this . _isInit ) {
73
79
this . _remove ( ) ;
74
80
}
75
81
76
- var self = this ;
77
-
78
- //hide the textarea that is me so that no one sees it
79
- self . getDOMNode ( ) . style . hidden = "hidden" ;
82
+ // hide the textarea that is me so that no one sees it
83
+ this . getDOMNode ( ) . style . hidden = 'hidden' ;
80
84
81
85
config . selector = '#' + this . id ;
82
- config . setup = function ( editor ) {
83
- EVENTS . forEach ( function ( event , index ) {
84
- var handler = self . props [ HANDLER_NAMES [ index ] ] ;
86
+ config . setup = ( editor ) => {
87
+ EVENTS . forEach ( ( event , index ) => {
88
+ const handler = this . props [ HANDLER_NAMES [ index ] ] ;
85
89
if ( typeof handler !== 'function' ) return ;
86
- editor . on ( event , function ( e ) {
90
+ editor . on ( event , ( e ) => {
87
91
// native DOM events don't have access to the editor so we pass it here
88
92
handler ( e , editor ) ;
89
93
} ) ;
90
94
} ) ;
91
95
// need to set content here because the textarea will still have the
92
96
// old `this.props.content`
93
97
if ( content ) {
94
- editor . on ( 'init' , function ( ) {
98
+ editor . on ( 'init' , ( ) => {
95
99
editor . setContent ( content ) ;
96
100
} ) ;
97
101
}
98
102
} ;
99
103
100
104
tinymce . init ( config ) ;
101
105
102
- self . getDOMNode ( ) . style . hidden = "" ;
106
+ this . getDOMNode ( ) . style . hidden = '' ;
103
107
104
108
this . _isInit = true ;
105
109
} ,
106
110
107
- _remove : function ( ) {
108
- tinymce . EditorManager . execCommand ( " mceRemoveEditor" , true , this . id ) ;
111
+ _remove ( ) {
112
+ tinymce . EditorManager . execCommand ( ' mceRemoveEditor' , true , this . id ) ;
109
113
this . _isInit = false ;
110
- } ,
111
-
112
- render : function ( ) {
113
- return DOM . textarea ( {
114
- id : this . id ,
115
- defaultValue : this . props . content
116
- } ) ;
117
114
}
118
115
} ) ;
119
116
120
- //add handler propTypes
121
- HANDLER_NAMES . forEach ( function ( name ) {
117
+ // add handler propTypes
118
+ HANDLER_NAMES . forEach ( ( name ) => {
122
119
TinyMCE . propTypes [ name ] = React . PropTypes . func ;
123
120
} ) ;
124
121
0 commit comments