2016-06-16 19:20:36 -03:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-09-12 11:14:21 +02:00
|
|
|
import registry from '../../lib/registry';
|
2016-08-11 18:21:32 -03:00
|
|
|
import RawEditor from './MarkdownControlElements/RawEditor';
|
2016-08-11 11:27:09 -03:00
|
|
|
import VisualEditor from './MarkdownControlElements/VisualEditor';
|
2016-08-18 10:51:38 -03:00
|
|
|
import { processEditorPlugins } from './richText';
|
2016-08-11 18:21:32 -03:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { switchVisualMode } from '../../actions/editor';
|
2016-08-03 10:30:42 -03:00
|
|
|
|
2016-08-01 16:41:55 -03:00
|
|
|
class MarkdownControl extends React.Component {
|
2016-10-03 14:33:48 +02:00
|
|
|
static propTypes = {
|
|
|
|
editor: PropTypes.object.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
onAddMedia: PropTypes.func.isRequired,
|
|
|
|
getMedia: PropTypes.func.isRequired,
|
|
|
|
switchVisualMode: PropTypes.func.isRequired,
|
|
|
|
value: PropTypes.node,
|
|
|
|
};
|
2016-08-11 18:21:32 -03:00
|
|
|
|
2016-11-01 16:55:21 -07:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = { mode: 'visual' };
|
|
|
|
}
|
|
|
|
|
2016-08-18 10:51:38 -03:00
|
|
|
componentWillMount() {
|
2016-09-12 11:14:21 +02:00
|
|
|
processEditorPlugins(registry.getEditorComponents());
|
2016-08-18 10:51:38 -03:00
|
|
|
}
|
|
|
|
|
2016-11-01 16:55:21 -07:00
|
|
|
handleMode = (mode) => {
|
|
|
|
this.setState({ mode });
|
2016-10-03 14:25:27 +02:00
|
|
|
};
|
2016-08-11 18:21:32 -03:00
|
|
|
|
2016-09-27 13:07:52 +02:00
|
|
|
render() {
|
2016-11-01 16:55:21 -07:00
|
|
|
const { onChange, onAddMedia, onRemoveMedia, getMedia, value } = this.props;
|
|
|
|
const { mode } = this.state;
|
|
|
|
if (mode === 'visual') {
|
2016-08-11 18:21:32 -03:00
|
|
|
return (
|
2016-10-18 12:32:39 -02:00
|
|
|
<div className="cms-editor-visual">
|
2016-08-11 18:21:32 -03:00
|
|
|
<VisualEditor
|
2016-10-03 16:57:48 +02:00
|
|
|
onChange={onChange}
|
|
|
|
onAddMedia={onAddMedia}
|
2016-10-22 23:12:21 +03:00
|
|
|
onRemoveMedia={onRemoveMedia}
|
2016-11-01 16:55:21 -07:00
|
|
|
onMode={this.handleMode}
|
2016-10-03 16:57:48 +02:00
|
|
|
getMedia={getMedia}
|
|
|
|
value={value}
|
2016-08-11 18:21:32 -03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-11-01 16:55:21 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="cms-editor-raw">
|
|
|
|
<RawEditor
|
|
|
|
onChange={onChange}
|
|
|
|
onAddMedia={onAddMedia}
|
|
|
|
onRemoveMedia={onRemoveMedia}
|
|
|
|
onMode={this.handleMode}
|
|
|
|
getMedia={getMedia}
|
|
|
|
value={value}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2016-08-11 18:21:32 -03:00
|
|
|
}
|
2016-05-30 16:55:32 -07:00
|
|
|
}
|
2016-06-16 19:20:36 -03:00
|
|
|
|
2016-08-11 18:21:32 -03:00
|
|
|
export default connect(
|
|
|
|
state => ({ editor: state.editor }),
|
|
|
|
{ switchVisualMode }
|
|
|
|
)(MarkdownControl);
|