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