2019-02-01 10:44:10 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { Utils } from './utils/utils';
|
2019-03-28 02:59:43 +00:00
|
|
|
import SharedFileView from './components/shared-file-view/shared-file-view';
|
|
|
|
import SharedFileViewTip from './components/shared-file-view/shared-file-view-tip';
|
2019-02-01 10:44:10 +00:00
|
|
|
|
2022-12-21 05:30:29 +00:00
|
|
|
import { UnControlled as CodeMirror } from 'react-codemirror2';
|
2019-02-01 10:44:10 +00:00
|
|
|
import 'codemirror/mode/javascript/javascript';
|
|
|
|
import 'codemirror/mode/css/css';
|
|
|
|
import 'codemirror/mode/clike/clike';
|
|
|
|
import 'codemirror/mode/php/php';
|
|
|
|
import 'codemirror/mode/sql/sql';
|
|
|
|
import 'codemirror/mode/vue/vue';
|
|
|
|
import 'codemirror/mode/xml/xml';
|
|
|
|
import 'codemirror/mode/go/go';
|
|
|
|
import 'codemirror/mode/python/python';
|
|
|
|
import 'codemirror/mode/htmlmixed/htmlmixed';
|
2019-03-28 02:59:43 +00:00
|
|
|
import 'codemirror/lib/codemirror.css';
|
|
|
|
|
|
|
|
import './css/text-file-view.css';
|
2019-02-01 10:44:10 +00:00
|
|
|
|
2019-03-28 02:59:43 +00:00
|
|
|
const { err, fileExt, fileContent } = window.shared.pageOptions;
|
2019-02-01 10:44:10 +00:00
|
|
|
|
2019-03-28 02:59:43 +00:00
|
|
|
const options = {
|
|
|
|
lineNumbers: true,
|
|
|
|
mode: Utils.chooseLanguage(fileExt),
|
2019-02-01 10:44:10 +00:00
|
|
|
extraKeys: {'Ctrl': 'autocomplete'},
|
|
|
|
theme: 'default',
|
|
|
|
textWrapping: true,
|
|
|
|
lineWrapping: true,
|
2019-03-28 02:59:43 +00:00
|
|
|
readOnly: true,
|
|
|
|
cursorBlinkRate: -1 // hide the cursor
|
2019-02-01 10:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SharedFileViewText extends React.Component {
|
2019-03-28 02:59:43 +00:00
|
|
|
render() {
|
|
|
|
return <SharedFileView content={<FileContent />} />;
|
2019-02-19 07:14:50 +00:00
|
|
|
}
|
2019-03-28 02:59:43 +00:00
|
|
|
}
|
2019-02-19 07:14:50 +00:00
|
|
|
|
2019-03-28 02:59:43 +00:00
|
|
|
class FileContent extends React.Component {
|
2019-02-01 10:44:10 +00:00
|
|
|
render() {
|
2019-03-28 02:59:43 +00:00
|
|
|
if (err) {
|
|
|
|
return <SharedFileViewTip />;
|
|
|
|
}
|
|
|
|
|
2019-02-01 10:44:10 +00:00
|
|
|
return (
|
2019-03-28 02:59:43 +00:00
|
|
|
<div className="shared-file-view-body text-file-view">
|
|
|
|
<CodeMirror
|
|
|
|
ref="code-mirror-editor"
|
|
|
|
value={fileContent}
|
|
|
|
options={options}
|
|
|
|
/>
|
2019-02-01 10:44:10 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 02:59:43 +00:00
|
|
|
ReactDOM.render(
|
2019-02-01 10:44:10 +00:00
|
|
|
<SharedFileViewText />,
|
|
|
|
document.getElementById('wrapper')
|
|
|
|
);
|