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' ;
66
77// Include all of the Native DOM and custom events from:
88// https://github.com/tinymce/tinymce/blob/master/tools/docs/tinymce.Editor.js#L5-L12
9- var EVENTS = [
9+ const EVENTS = [
1010 'focusin' , 'focusout' , 'click' , 'dblclick' , 'mousedown' , 'mouseup' ,
1111 'mousemove' , 'mouseover' , 'beforepaste' , 'paste' , 'cut' , 'copy' ,
1212 'selectionchange' , 'mouseout' , 'mouseenter' , 'mouseleave' , 'keydown' ,
@@ -24,101 +24,101 @@ var EVENTS = [
2424// Note: because the capitalization of the events is weird, we're going to get
2525// some inconsistently-named handlers, for example compare:
2626// '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 ) ;
2929} ) ;
3030
31- var TinyMCE = React . createClass ( {
31+ const TinyMCE = React . createClass ( {
3232 displayName : 'TinyMCE' ,
3333
3434 propTypes : {
3535 config : React . PropTypes . object ,
36- content : React . PropTypes . string ,
36+ content : React . PropTypes . string
3737 } ,
3838
39- getDefaultProps : function ( ) {
39+ getDefaultProps ( ) {
4040 return {
4141 config : { } ,
4242 content : ''
4343 } ;
4444 } ,
4545
46- componentWillMount : function ( ) {
46+ componentWillMount ( ) {
4747 this . id = this . id || uuid ( ) ;
4848 } ,
4949
50- componentDidMount : function ( ) {
50+ componentDidMount ( ) {
5151 this . _init ( this . props . config ) ;
5252 } ,
5353
54- componentWillUnmount : function ( ) {
54+ componentWillUnmount ( ) {
5555 this . _remove ( ) ;
5656 } ,
5757
58- componentWillReceiveProps : function ( nextProps ) {
58+ componentWillReceiveProps ( nextProps ) {
5959 if ( ! isEqual ( this . props . config , nextProps . config ) ) {
6060 this . _init ( nextProps . config , nextProps . content ) ;
6161 }
6262 } ,
6363
64- shouldComponentUpdate : function ( nextProps , nextState ) {
64+ shouldComponentUpdate ( nextProps ) {
6565 return (
6666 ! isEqual ( this . props . content , nextProps . content ) ||
6767 ! isEqual ( this . props . config , nextProps . config )
6868 ) ;
6969 } ,
7070
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 ) {
7281 if ( this . _isInit ) {
7382 this . _remove ( ) ;
7483 }
7584
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' ;
8087
8188 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 ] ] ;
8592 if ( typeof handler !== 'function' ) return ;
86- editor . on ( event , function ( e ) {
93+ editor . on ( event , ( e ) => {
8794 // native DOM events don't have access to the editor so we pass it here
8895 handler ( e , editor ) ;
8996 } ) ;
9097 } ) ;
9198 // need to set content here because the textarea will still have the
9299 // old `this.props.content`
93100 if ( content ) {
94- editor . on ( 'init' , function ( ) {
101+ editor . on ( 'init' , ( ) => {
95102 editor . setContent ( content ) ;
96103 } ) ;
97104 }
98105 } ;
99106
100107 tinymce . init ( config ) ;
101108
102- self . getDOMNode ( ) . style . hidden = "" ;
109+ findDOMNode ( this ) . style . hidden = '' ;
103110
104111 this . _isInit = true ;
105112 } ,
106113
107- _remove : function ( ) {
108- tinymce . EditorManager . execCommand ( " mceRemoveEditor" , true , this . id ) ;
114+ _remove ( ) {
115+ tinymce . EditorManager . execCommand ( ' mceRemoveEditor' , true , this . id ) ;
109116 this . _isInit = false ;
110- } ,
111-
112- render : function ( ) {
113- return DOM . textarea ( {
114- id : this . id ,
115- defaultValue : this . props . content
116- } ) ;
117117 }
118118} ) ;
119119
120- //add handler propTypes
121- HANDLER_NAMES . forEach ( function ( name ) {
120+ // add handler propTypes
121+ HANDLER_NAMES . forEach ( ( name ) => {
122122 TinyMCE . propTypes [ name ] = React . PropTypes . func ;
123123} ) ;
124124
0 commit comments