Skip to content

Commit 0835f12

Browse files
committed
[changed] supporting React 0.14.0
1 parent 51906f8 commit 0835f12

File tree

9 files changed

+63
-75
lines changed

9 files changed

+63
-75
lines changed

examples/basic/app.js

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

4-
var STYLES = {
4+
const STYLES = {
55
container: {
66
fontFamily: 'Helvetica Neue, sans-serif',
77
padding: '0 25px'
@@ -16,20 +16,20 @@ var STYLES = {
1616
}
1717
};
1818

19-
var App = React.createClass({
20-
getInitialState: function () {
19+
const App = React.createClass({
20+
getInitialState() {
2121
return {
2222
content: '<p><strong>Welcome to react-tinymce</strong></p>'
2323
};
2424
},
2525

26-
handleEditorChange: function (e) {
26+
handleEditorChange(e) {
2727
this.setState({
2828
content: e.target.getContent()
2929
});
3030
},
31-
32-
render: function () {
31+
32+
render() {
3333
return (
3434
<div style={STYLES.container}>
3535
<h1>react-tinymce</h1>

lib/components/TinyMCE.js

+35-38
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
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';
65

76
// Include all of the Native DOM and custom events from:
87
// https://github.com/tinymce/tinymce/blob/master/tools/docs/tinymce.Editor.js#L5-L12
9-
var EVENTS = [
8+
const EVENTS = [
109
'focusin', 'focusout', 'click', 'dblclick', 'mousedown', 'mouseup',
1110
'mousemove', 'mouseover', 'beforepaste', 'paste', 'cut', 'copy',
1211
'selectionchange', 'mouseout', 'mouseenter', 'mouseleave', 'keydown',
@@ -24,101 +23,99 @@ var EVENTS = [
2423
// Note: because the capitalization of the events is weird, we're going to get
2524
// some inconsistently-named handlers, for example compare:
2625
// '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);
2928
});
3029

31-
var TinyMCE = React.createClass({
30+
const TinyMCE = React.createClass({
3231
displayName: 'TinyMCE',
3332

3433
propTypes: {
3534
config: React.PropTypes.object,
36-
content: React.PropTypes.string,
35+
content: React.PropTypes.string
3736
},
3837

39-
getDefaultProps: function () {
38+
getDefaultProps() {
4039
return {
4140
config: {},
4241
content: ''
4342
};
4443
},
4544

46-
componentWillMount: function () {
45+
componentWillMount() {
4746
this.id = this.id || uuid();
4847
},
4948

50-
componentDidMount: function () {
49+
componentDidMount() {
5150
this._init(this.props.config);
5251
},
5352

54-
componentWillUnmount: function () {
53+
componentWillUnmount() {
5554
this._remove();
5655
},
5756

58-
componentWillReceiveProps: function (nextProps) {
57+
componentWillReceiveProps(nextProps) {
5958
if (!isEqual(this.props.config, nextProps.config)) {
6059
this._init(nextProps.config, nextProps.content);
6160
}
6261
},
6362

64-
shouldComponentUpdate: function (nextProps, nextState) {
63+
shouldComponentUpdate(nextProps) {
6564
return (
6665
!isEqual(this.props.content, nextProps.content) ||
6766
!isEqual(this.props.config, nextProps.config)
6867
);
6968
},
7069

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) {
7278
if (this._isInit) {
7379
this._remove();
7480
}
7581

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';
8084

8185
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]];
8589
if (typeof handler !== 'function') return;
86-
editor.on(event, function(e) {
90+
editor.on(event, (e) => {
8791
// native DOM events don't have access to the editor so we pass it here
8892
handler(e, editor);
8993
});
9094
});
9195
// need to set content here because the textarea will still have the
9296
// old `this.props.content`
9397
if (content) {
94-
editor.on('init', function() {
98+
editor.on('init', () => {
9599
editor.setContent(content);
96100
});
97101
}
98102
};
99103

100104
tinymce.init(config);
101105

102-
self.getDOMNode().style.hidden = "";
106+
this.getDOMNode().style.hidden = '';
103107

104108
this._isInit = true;
105109
},
106110

107-
_remove: function () {
108-
tinymce.EditorManager.execCommand("mceRemoveEditor", true, this.id);
111+
_remove() {
112+
tinymce.EditorManager.execCommand('mceRemoveEditor', true, this.id);
109113
this._isInit = false;
110-
},
111-
112-
render: function () {
113-
return DOM.textarea({
114-
id: this.id,
115-
defaultValue: this.props.content
116-
});
117114
}
118115
});
119116

120-
//add handler propTypes
121-
HANDLER_NAMES.forEach(function (name) {
117+
// add handler propTypes
118+
HANDLER_NAMES.forEach((name) => {
122119
TinyMCE.propTypes[name] = React.PropTypes.func;
123120
});
124121

+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

+6-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,13 @@
1414
"author": "Matt Zabriskie",
1515
"license": "MIT",
1616
"peerDependencies": {
17-
"react": "^0.13.3"
17+
"react": "^0.14.0"
1818
},
1919
"devDependencies": {
20-
"rackt-cli": "^0.2.0",
21-
"react": "^0.13.3"
20+
"rackt-cli": "^0.5.2",
21+
"react": "^0.14.0"
2222
},
2323
"dependencies": {
2424
"lodash": "^3.9.3"
2525
}
26-
}
26+
}

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)