import React from 'react'; import PropTypes from 'prop-types'; import { EditorContext, Toolbar, MarkdownEditor, UserHelp } from '@seafile/seafile-editor'; import SidePanel from './side-panel'; import '../css/rich-editor.css'; const propTypes = { scriptSource: PropTypes.string, markdownContent: PropTypes.string, value: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), issues: PropTypes.object, fileInfo: PropTypes.object, readOnly: PropTypes.bool, editorApi: PropTypes.object, onSave: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, resetRichValue: PropTypes.func, fileTagList: PropTypes.array, onFileTagChanged: PropTypes.func, participants: PropTypes.array, onParticipantsChange: PropTypes.func, openDialogs: PropTypes.func, }; class RichMarkdownEditor extends React.Component { constructor(props) { super(props); this.state = { isShowSidePanel: false, isShowHelpPanel: false, }; window.richMarkdownEditor = this; } toggleSidePanel = () => { this.setState({ isShowSidePanel: !this.state.isShowSidePanel, isShowHelpPanel: false, }); }; showHelpDialog = () => { this.setState({isShowSidePanel: false, isShowHelpPanel: true}); }; hideHelpDialog = () => { this.setState({isShowHelpPanel: false}); }; insertRepoFile = () => { if (this.props.readOnly) return; this.props.openDialogs && this.props.openDialogs('insert_file'); }; addLink = (fileName, url, isImage) => { const editorRef = EditorContext.getEditorRef(); editorRef.addLink(fileName, url, isImage); }; render() { const hasSidePanel = true; const { isShowSidePanel, isShowHelpPanel } = this.state; const { value } = this.props; const isShowHelpWrapper = isShowSidePanel || isShowHelpPanel; const helpWrapperStyle = isShowHelpPanel ? {width: '350px'} : {}; return (
{isShowSidePanel && ( )} {isShowHelpPanel && }
); } } RichMarkdownEditor.propTypes = propTypes; export default RichMarkdownEditor;