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-08-18 10:51:38 -03:00
|
|
|
componentWillMount() {
|
2016-09-12 11:14:21 +02:00
|
|
|
this.useRawEditor();
|
|
|
|
processEditorPlugins(registry.getEditorComponents());
|
2016-08-18 10:51:38 -03:00
|
|
|
}
|
|
|
|
|
2016-09-27 13:07:52 +02:00
|
|
|
useVisualEditor = () => {
|
2016-08-11 18:21:32 -03:00
|
|
|
this.props.switchVisualMode(true);
|
2016-10-03 14:25:27 +02:00
|
|
|
};
|
2016-08-11 18:21:32 -03:00
|
|
|
|
2016-09-27 13:07:52 +02:00
|
|
|
useRawEditor = () => {
|
2016-08-11 18:21:32 -03:00
|
|
|
this.props.switchVisualMode(false);
|
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-10-22 23:12:21 +03:00
|
|
|
const { editor, onChange, onAddMedia, onRemoveMedia, getMedia, value } = this.props;
|
2016-08-11 18:21:32 -03:00
|
|
|
if (editor.get('useVisualMode')) {
|
|
|
|
return (
|
2016-10-18 12:32:39 -02:00
|
|
|
<div className="cms-editor-visual">
|
2016-09-12 11:14:21 +02:00
|
|
|
{null && <button onClick={this.useRawEditor}>Switch to Raw Editor</button>}
|
2016-08-11 18:21:32 -03:00
|
|
|
<VisualEditor
|
2016-10-03 16:57:48 +02:00
|
|
|
onChange={onChange}
|
|
|
|
onAddMedia={onAddMedia}
|
|
|
|
getMedia={getMedia}
|
|
|
|
registeredComponents={editor.get('registeredComponents')}
|
|
|
|
value={value}
|
2016-08-11 18:21:32 -03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2016-10-18 12:32:39 -02:00
|
|
|
<div className="cms-editor-raw">
|
2016-09-12 11:14:21 +02:00
|
|
|
{null && <button onClick={this.useVisualEditor}>Switch to Visual Editor</button>}
|
2016-08-11 18:21:32 -03:00
|
|
|
<RawEditor
|
2016-10-03 16:57:48 +02:00
|
|
|
onChange={onChange}
|
|
|
|
onAddMedia={onAddMedia}
|
2016-10-22 23:12:21 +03:00
|
|
|
onRemoveMedia={onRemoveMedia}
|
2016-10-03 16:57:48 +02:00
|
|
|
getMedia={getMedia}
|
|
|
|
value={value}
|
2016-08-11 18:21:32 -03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
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);
|