mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 16:31:13 +00:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import CodeMirror from '@uiw/react-codemirror';
|
|
import { getLanguageExtensions } from './languages';
|
|
import { myTheme } from './theme';
|
|
|
|
const DEFAULT_CODEMIRROR_OPTIONS = {
|
|
lineNumbers: true,
|
|
highlightActiveLineGutter: false,
|
|
highlightActiveLine: false,
|
|
};
|
|
|
|
const propTypes = {
|
|
fileExt: PropTypes.string,
|
|
value: PropTypes.string,
|
|
readOnly: PropTypes.bool,
|
|
onChange: PropTypes.func,
|
|
};
|
|
|
|
class SeafileCodeMirror extends React.Component {
|
|
|
|
static defaultProps = {
|
|
readOnly: true,
|
|
};
|
|
|
|
onChange = (value) => {
|
|
this.props.onChange && this.props.onChange(value);
|
|
};
|
|
|
|
render() {
|
|
const { value, readOnly, fileExt } = this.props;
|
|
const extensions = [...getLanguageExtensions(fileExt).filter(item => item !== null)];
|
|
return (
|
|
<div className='seafile-code-mirror-container'>
|
|
<CodeMirror
|
|
value={value}
|
|
basicSetup={DEFAULT_CODEMIRROR_OPTIONS}
|
|
theme={myTheme}
|
|
readOnly={readOnly}
|
|
extensions={extensions}
|
|
onChange={this.onChange}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
SeafileCodeMirror.propTypes = propTypes;
|
|
|
|
export default SeafileCodeMirror;
|