static-cms/src/components/Widgets/MarkdownControl.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import registry from '../../lib/registry';
2016-08-11 18:21:32 -03:00
import RawEditor from './MarkdownControlElements/RawEditor';
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() {
this.useRawEditor();
processEditorPlugins(registry.getEditorComponents());
2016-08-18 10:51:38 -03: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
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
render() {
2016-08-11 18:21:32 -03:00
const { editor, onChange, onAddMedia, getMedia, value } = this.props;
if (editor.get('useVisualMode')) {
return (
<div className='cms-editor-visual'>
{null && <button onClick={this.useRawEditor}>Switch to Raw Editor</button>}
2016-08-11 18:21:32 -03:00
<VisualEditor
onChange={onChange}
onAddMedia={onAddMedia}
getMedia={getMedia}
registeredComponents={editor.get('registeredComponents')}
value={value}
2016-08-11 18:21:32 -03:00
/>
</div>
);
} else {
return (
<div className='cms-editor-raw'>
{null && <button onClick={this.useVisualEditor}>Switch to Visual Editor</button>}
2016-08-11 18:21:32 -03:00
<RawEditor
onChange={onChange}
onAddMedia={onAddMedia}
getMedia={getMedia}
value={value}
2016-08-11 18:21:32 -03:00
/>
</div>
);
}
}
2016-05-30 16:55:32 -07:00
}
2016-08-11 18:21:32 -03:00
export default connect(
state => ({ editor: state.editor }),
{ switchVisualMode }
)(MarkdownControl);