1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 09:51:26 +00:00
Files
seahub/frontend/src/pages/markdown-editor/rich-markdown-editor/index.js

114 lines
3.4 KiB
JavaScript
Raw Normal View History

2022-05-20 16:26:53 +08:00
import React from 'react';
import PropTypes from 'prop-types';
2023-01-12 10:40:57 +08:00
import { EditorContext, Toolbar, MarkdownEditor, UserHelp } from '@seafile/seafile-editor';
2022-05-20 16:26:53 +08:00
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,
2022-05-20 17:21:01 +08:00
openDialogs: PropTypes.func,
2022-05-20 16:26:53 +08:00
};
2022-05-20 17:21:01 +08:00
class RichMarkdownEditor extends React.Component {
2022-05-20 16:26:53 +08:00
constructor(props) {
super(props);
this.state = {
isShowSidePanel: false,
isShowHelpPanel: false,
};
window.richMarkdownEditor = this;
}
toggleSidePanel = () => {
this.setState({
isShowSidePanel: !this.state.isShowSidePanel,
isShowHelpPanel: false,
});
};
2022-05-20 16:26:53 +08:00
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');
};
2022-05-20 16:26:53 +08:00
addLink = (fileName, url, isImage) => {
2023-01-12 10:40:57 +08:00
const editorRef = EditorContext.getEditorRef();
2022-05-20 16:26:53 +08:00
editorRef.addLink(fileName, url, isImage);
};
2022-05-20 16:26:53 +08:00
render() {
const hasSidePanel = true;
const { isShowSidePanel, isShowHelpPanel } = this.state;
const { value } = this.props;
const isShowHelpWrapper = isShowSidePanel || isShowHelpPanel;
const helpWrapperStyle = isShowHelpPanel ? {width: '350px'} : {};
return (
<div className='seafile-markdown-editor'>
<div className='markdown-editor-toolbar'>
<Toolbar
2022-05-20 16:26:53 +08:00
hasSidePanel={hasSidePanel}
isShowSidePanel={isShowSidePanel}
toggleSidePanel={this.toggleSidePanel}
insertRepoFile={this.insertRepoFile}
/>
</div>
<div className='markdown-editor-content'>
<div className={`markdown-editor-wrapper ${isShowHelpWrapper ? '' : 'full-screen'}`}>
<MarkdownEditor
scriptSource={this.props.scriptSource}
value={value}
2022-05-25 15:22:43 +08:00
onSave={this.props.onSave}
editorApi={this.props.editorApi}
2022-05-20 16:26:53 +08:00
onChange={this.props.onChange}
resetRichValue={this.props.resetRichValue}
/>
</div>
<div className={`markdown-help-wrapper ${isShowHelpWrapper ? 'show' : ''}`} style={helpWrapperStyle}>
{isShowSidePanel && (
<SidePanel
2022-05-20 16:26:53 +08:00
document={value}
fileInfo={this.props.fileInfo}
fileTagList={this.props.fileTagList}
onFileTagChanged={this.props.onFileTagChanged}
participants={this.props.participants}
onParticipantsChange={this.props.onParticipantsChange}
/>
)}
{isShowHelpPanel && <UserHelp hideHelpDialog={this.hideHelpDialog} />}
</div>
</div>
</div>
);
}
}
2022-05-20 17:21:01 +08:00
RichMarkdownEditor.propTypes = propTypes;
2022-05-20 16:26:53 +08:00
2022-05-20 17:21:01 +08:00
export default RichMarkdownEditor;