Skip to content

Commit 5aebd62

Browse files
committed
[changed] supporting React 0.14.0
1 parent 51906f8 commit 5aebd62

File tree

9 files changed

+70
-76
lines changed

9 files changed

+70
-76
lines changed

examples/basic/app.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
var React = require('react');
2-
var TinyMCE = require('../../lib/main');
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import TinyMCE from '../../lib/main';
34

4-
var STYLES = {
5+
const STYLES = {
56
container: {
67
fontFamily: 'Helvetica Neue, sans-serif',
78
padding: '0 25px'
@@ -16,20 +17,20 @@ var STYLES = {
1617
}
1718
};
1819

19-
var App = React.createClass({
20-
getInitialState: function () {
20+
const App = React.createClass({
21+
getInitialState() {
2122
return {
2223
content: '<p><strong>Welcome to react-tinymce</strong></p>'
2324
};
2425
},
2526

26-
handleEditorChange: function (e) {
27+
handleEditorChange(e) {
2728
this.setState({
2829
content: e.target.getContent()
2930
});
3031
},
31-
32-
render: function () {
32+
33+
render() {
3334
return (
3435
<div style={STYLES.container}>
3536
<h1>react-tinymce</h1>
@@ -45,4 +46,4 @@ var App = React.createClass({
4546
}
4647
});
4748

48-
React.render(<App/>, document.getElementById('example'));
49+
ReactDOM.render(<App/>, document.getElementById('example'));

lib/components/TinyMCE.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// import React 'react';
2+
// import TestUtils from 'react-addons-test-utils';
3+
// import TinyMCE from '../..//main';
4+
import { equal } from 'assert';
5+
6+
/* eslint func-names:0 */
7+
describe('react-tinymce', function() {
8+
it('should render', function() {
9+
equal(true, true);
10+
});
11+
});
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = function uc_first(str) {
1+
export default function ucFirst(str) {
22
return str[0].toUpperCase() + str.substring(1);
3-
};
3+
}

lib/helpers/uuid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var count = 0;
1+
let count = 0;
22
module.exports = function uuid() {
33
return 'react-tinymce-' + count++;
44
};

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "React TinyMCE component",
55
"main": "lib/main.js",
66
"scripts": {
7-
"test": "node_modules/.bin/rackt test --ci --browsers Firefox",
8-
"start": "node_modules/.bin/rackt dev"
7+
"test": "node_modules/.bin/rackt test --single-run --browsers Firefox",
8+
"start": "node_modules/.bin/rackt server"
99
},
1010
"keywords": [
1111
"tinymce",
@@ -14,13 +14,15 @@
1414
"author": "Matt Zabriskie",
1515
"license": "MIT",
1616
"peerDependencies": {
17-
"react": "^0.13.3"
17+
"react": "^0.14.0",
18+
"react-dom": "^0.14.0"
1819
},
1920
"devDependencies": {
20-
"rackt-cli": "^0.2.0",
21-
"react": "^0.13.3"
21+
"rackt-cli": "^0.5.2",
22+
"react": "^0.14.0",
23+
"react-dom": "^0.14.0"
2224
},
2325
"dependencies": {
2426
"lodash": "^3.9.3"
2527
}
26-
}
28+
}

specs/TinyMCE.spec.js

-10
This file was deleted.

specs/helper.js

-9
This file was deleted.

specs/main.js

-1
This file was deleted.

0 commit comments

Comments
 (0)