Skip to content

Commit

Permalink
[changed] supporting React 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabriskie committed Oct 22, 2015
1 parent 51906f8 commit 0835f12
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 75 deletions.
16 changes: 8 additions & 8 deletions examples/basic/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var React = require('react');
var TinyMCE = require('../../lib/main');
import React from 'react';
import TinyMCE from '../../lib/main';

var STYLES = {
const STYLES = {
container: {
fontFamily: 'Helvetica Neue, sans-serif',
padding: '0 25px'
Expand All @@ -16,20 +16,20 @@ var STYLES = {
}
};

var App = React.createClass({
getInitialState: function () {
const App = React.createClass({
getInitialState() {
return {
content: '<p><strong>Welcome to react-tinymce</strong></p>'
};
},

handleEditorChange: function (e) {
handleEditorChange(e) {
this.setState({
content: e.target.getContent()
});
},
render: function () {

render() {
return (
<div style={STYLES.container}>
<h1>react-tinymce</h1>
Expand Down
73 changes: 35 additions & 38 deletions lib/components/TinyMCE.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var React = require('react');
var DOM = React.DOM;
var isEqual = require('lodash/lang/isEqual');
var uuid = require('../helpers/uuid');
var uc_first = require('../helpers/uc_first');
import React, { DOM } from 'react';
import isEqual from 'lodash/lang/isEqual';
import uuid from '../helpers/uuid';
import ucFirst from '../helpers/ucFirst';

// Include all of the Native DOM and custom events from:
// https://github.com/tinymce/tinymce/blob/master/tools/docs/tinymce.Editor.js#L5-L12
var EVENTS = [
const EVENTS = [
'focusin', 'focusout', 'click', 'dblclick', 'mousedown', 'mouseup',
'mousemove', 'mouseover', 'beforepaste', 'paste', 'cut', 'copy',
'selectionchange', 'mouseout', 'mouseenter', 'mouseleave', 'keydown',
Expand All @@ -24,101 +23,99 @@ var EVENTS = [
// Note: because the capitalization of the events is weird, we're going to get
// some inconsistently-named handlers, for example compare:
// 'onMouseleave' and 'onNodeChange'
var HANDLER_NAMES = EVENTS.map(function(event) {
return 'on' + uc_first(event);
const HANDLER_NAMES = EVENTS.map((event) => {
return 'on' + ucFirst(event);
});

var TinyMCE = React.createClass({
const TinyMCE = React.createClass({
displayName: 'TinyMCE',

propTypes: {
config: React.PropTypes.object,
content: React.PropTypes.string,
content: React.PropTypes.string
},

getDefaultProps: function () {
getDefaultProps() {
return {
config: {},
content: ''
};
},

componentWillMount: function () {
componentWillMount() {
this.id = this.id || uuid();
},

componentDidMount: function () {
componentDidMount() {
this._init(this.props.config);
},

componentWillUnmount: function () {
componentWillUnmount() {
this._remove();
},

componentWillReceiveProps: function (nextProps) {
componentWillReceiveProps(nextProps) {
if (!isEqual(this.props.config, nextProps.config)) {
this._init(nextProps.config, nextProps.content);
}
},

shouldComponentUpdate: function (nextProps, nextState) {
shouldComponentUpdate(nextProps) {
return (
!isEqual(this.props.content, nextProps.content) ||
!isEqual(this.props.config, nextProps.config)
);
},

_init: function (config, content) {
render() {
return DOM.textarea({
id: this.id,
defaultValue: this.props.content
});
},

_init(config, content) {
if (this._isInit) {
this._remove();
}

var self = this;

//hide the textarea that is me so that no one sees it
self.getDOMNode().style.hidden = "hidden";
// hide the textarea that is me so that no one sees it
this.getDOMNode().style.hidden = 'hidden';

config.selector = '#' + this.id;
config.setup = function (editor) {
EVENTS.forEach(function (event, index) {
var handler = self.props[HANDLER_NAMES[index]];
config.setup = (editor) => {
EVENTS.forEach((event, index) => {
const handler = this.props[HANDLER_NAMES[index]];
if (typeof handler !== 'function') return;
editor.on(event, function(e) {
editor.on(event, (e) => {
// native DOM events don't have access to the editor so we pass it here
handler(e, editor);
});
});
// need to set content here because the textarea will still have the
// old `this.props.content`
if (content) {
editor.on('init', function() {
editor.on('init', () => {
editor.setContent(content);
});
}
};

tinymce.init(config);

self.getDOMNode().style.hidden = "";
this.getDOMNode().style.hidden = '';

this._isInit = true;
},

_remove: function () {
tinymce.EditorManager.execCommand("mceRemoveEditor", true, this.id);
_remove() {
tinymce.EditorManager.execCommand('mceRemoveEditor', true, this.id);
this._isInit = false;
},

render: function () {
return DOM.textarea({
id: this.id,
defaultValue: this.props.content
});
}
});

//add handler propTypes
HANDLER_NAMES.forEach(function (name) {
// add handler propTypes
HANDLER_NAMES.forEach((name) => {
TinyMCE.propTypes[name] = React.PropTypes.func;
});

Expand Down
11 changes: 11 additions & 0 deletions lib/components/__tests__/TinyMCE-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// import React 'react';
// import TestUtils from 'react-addons-test-utils';
// import TinyMCE from '../..//main';
import { equal } from 'assert';

/* eslint func-names:0 */
describe('react-tinymce', function() {
it('should render', function() {
equal(true, true);
});
});
4 changes: 2 additions & 2 deletions lib/helpers/uc_first.js → lib/helpers/ucFirst.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function uc_first(str) {
export default function ucFirst(str) {
return str[0].toUpperCase() + str.substring(1);
};
}
2 changes: 1 addition & 1 deletion lib/helpers/uuid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var count = 0;
let count = 0;
module.exports = function uuid() {
return 'react-tinymce-' + count++;
};
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "React TinyMCE component",
"main": "lib/main.js",
"scripts": {
"test": "node_modules/.bin/rackt test --ci --browsers Firefox",
"start": "node_modules/.bin/rackt dev"
"test": "node_modules/.bin/rackt test --single-run --browsers Firefox",
"start": "node_modules/.bin/rackt server"
},
"keywords": [
"tinymce",
Expand All @@ -14,13 +14,13 @@
"author": "Matt Zabriskie",
"license": "MIT",
"peerDependencies": {
"react": "^0.13.3"
"react": "^0.14.0"
},
"devDependencies": {
"rackt-cli": "^0.2.0",
"react": "^0.13.3"
"rackt-cli": "^0.5.2",
"react": "^0.14.0"
},
"dependencies": {
"lodash": "^3.9.3"
}
}
}
10 changes: 0 additions & 10 deletions specs/TinyMCE.spec.js

This file was deleted.

9 changes: 0 additions & 9 deletions specs/helper.js

This file was deleted.

1 change: 0 additions & 1 deletion specs/main.js

This file was deleted.

0 comments on commit 0835f12

Please sign in to comment.