mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-08 00:21:23 +01:00
fix all typescript errors (#18)
This commit is contained in:
parent
baeafdce78
commit
7376ed2824
@ -97,7 +97,7 @@ class SimpleBlobRendererModel {
|
|||||||
this.reload_noDelay();
|
this.reload_noDelay();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reload_noDelay();
|
this.reload_noDelay();
|
||||||
}, delayMs);
|
}, delayMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ class SimpleBlobRendererModel {
|
|||||||
}
|
}
|
||||||
let rtnp = GlobalModel.readRemoteFile(this.context.screenId, this.context.lineId, path);
|
let rtnp = GlobalModel.readRemoteFile(this.context.screenId, this.context.lineId, path);
|
||||||
rtnp.then((file) => {
|
rtnp.then((file) => {
|
||||||
this.readOnly = file.readOnly;
|
this.readOnly = (file as any).readOnly;
|
||||||
this.dataBlob = file;
|
this.dataBlob = file;
|
||||||
mobx.action(() => {
|
mobx.action(() => {
|
||||||
this.loading.set(false);
|
this.loading.set(false);
|
||||||
|
@ -357,7 +357,6 @@ type RendererOpts = {
|
|||||||
idealSize: WindowSize;
|
idealSize: WindowSize;
|
||||||
termOpts: TermOptsType;
|
termOpts: TermOptsType;
|
||||||
termFontSize: number;
|
termFontSize: number;
|
||||||
readOnly: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type RendererOptsUpdate = {
|
type RendererOptsUpdate = {
|
||||||
@ -410,11 +409,16 @@ type RendererModel = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type SimpleBlobRendererComponent = React.ComponentType<{
|
type SimpleBlobRendererComponent = React.ComponentType<{
|
||||||
path: string;
|
|
||||||
data: Blob;
|
data: Blob;
|
||||||
|
readOnly?: boolean;
|
||||||
|
cmdstr?: string;
|
||||||
|
cwd?: string;
|
||||||
|
exitcode?: number;
|
||||||
context: RendererContext;
|
context: RendererContext;
|
||||||
opts: RendererOpts;
|
opts: RendererOpts;
|
||||||
savedHeight: number;
|
savedHeight: number;
|
||||||
|
scrollToBringIntoViewport?: () => void;
|
||||||
|
lineState?: LineStateType;
|
||||||
}>;
|
}>;
|
||||||
type FullRendererComponent = React.ComponentType<{ model: any }>;
|
type FullRendererComponent = React.ComponentType<{ model: any }>;
|
||||||
|
|
||||||
|
@ -9,9 +9,13 @@ function renderCmdText(text: string): any {
|
|||||||
return <span>⌘{text}</span>;
|
return <span>⌘{text}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// there is a global monaco variable (TODO get the correct TS type)
|
||||||
|
declare var monaco: any;
|
||||||
|
|
||||||
class SourceCodeRenderer extends React.Component<
|
class SourceCodeRenderer extends React.Component<
|
||||||
{
|
{
|
||||||
data: Blob;
|
data: Blob;
|
||||||
|
readOnly: boolean;
|
||||||
cmdstr: string;
|
cmdstr: string;
|
||||||
cwd: string;
|
cwd: string;
|
||||||
exitcode: number;
|
exitcode: number;
|
||||||
@ -21,7 +25,15 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
scrollToBringIntoViewport: () => void;
|
scrollToBringIntoViewport: () => void;
|
||||||
lineState: LineStateType;
|
lineState: LineStateType;
|
||||||
},
|
},
|
||||||
{}
|
{
|
||||||
|
code: string;
|
||||||
|
languages: string[];
|
||||||
|
selectedLanguage: string;
|
||||||
|
isSave: boolean;
|
||||||
|
isClosed: boolean;
|
||||||
|
editorHeight: number;
|
||||||
|
message: { status: string; text: string };
|
||||||
|
}
|
||||||
> {
|
> {
|
||||||
/**
|
/**
|
||||||
* codeCache is a Hashmap with key=screenId:lineId:filepath and value=code
|
* codeCache is a Hashmap with key=screenId:lineId:filepath and value=code
|
||||||
@ -32,9 +44,11 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
filePath;
|
filePath;
|
||||||
cacheKey;
|
cacheKey;
|
||||||
originalData;
|
originalData;
|
||||||
|
monacoEditor: any; // reference to mounted monaco editor. TODO need the correct type
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.editorRef = React.createRef();
|
this.monacoEditor = null;
|
||||||
this.state = {
|
this.state = {
|
||||||
code: null,
|
code: null,
|
||||||
languages: [],
|
languages: [],
|
||||||
@ -86,7 +100,6 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (detectedLanguage) {
|
if (detectedLanguage) {
|
||||||
this.editorRef.current = editor;
|
|
||||||
const model = editor.getModel();
|
const model = editor.getModel();
|
||||||
if (model) {
|
if (model) {
|
||||||
monaco.editor.setModelLanguage(model, detectedLanguage);
|
monaco.editor.setModelLanguage(model, detectedLanguage);
|
||||||
@ -96,6 +109,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleEditorDidMount = (editor, monaco) => {
|
handleEditorDidMount = (editor, monaco) => {
|
||||||
|
this.monacoEditor = editor;
|
||||||
this.setInitialLanguage(editor);
|
this.setInitialLanguage(editor);
|
||||||
this.setEditorHeight();
|
this.setEditorHeight();
|
||||||
editor.onKeyDown((e) => {
|
editor.onKeyDown((e) => {
|
||||||
@ -114,8 +128,8 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
const { screenId, lineId } = this.props.context;
|
const { screenId, lineId } = this.props.context;
|
||||||
const selectedLanguage = event.target.value;
|
const selectedLanguage = event.target.value;
|
||||||
this.setState({ selectedLanguage });
|
this.setState({ selectedLanguage });
|
||||||
if (this.editorRef.current) {
|
if (this.monacoEditor) {
|
||||||
const model = this.editorRef.current.getModel();
|
const model = this.monacoEditor.getModel();
|
||||||
if (model) {
|
if (model) {
|
||||||
monaco.editor.setModelLanguage(model, selectedLanguage);
|
monaco.editor.setModelLanguage(model, selectedLanguage);
|
||||||
GlobalCommandRunner.setLineState(
|
GlobalCommandRunner.setLineState(
|
||||||
@ -184,7 +198,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
};
|
};
|
||||||
|
|
||||||
setEditorHeight = () => {
|
setEditorHeight = () => {
|
||||||
const fullWindowHeight = parseInt(this.props.opts.maxSize.height);
|
const fullWindowHeight = this.props.opts.maxSize.height;
|
||||||
let _editorHeight = fullWindowHeight;
|
let _editorHeight = fullWindowHeight;
|
||||||
if (this.props.readOnly || this.state.isClosed) {
|
if (this.props.readOnly || this.state.isClosed) {
|
||||||
const noOfLines = Math.max(this.state.code.split("\n").length, 5);
|
const noOfLines = Math.max(this.state.code.split("\n").length, 5);
|
||||||
@ -195,7 +209,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { opts, exitcode, readOnly } = this.props;
|
const { opts, exitcode, readOnly } = this.props;
|
||||||
const { language, code, isSave, isClosed } = this.state;
|
const { selectedLanguage, code, isSave, isClosed } = this.state;
|
||||||
|
|
||||||
if (code == null)
|
if (code == null)
|
||||||
return <div className="renderer-container code-renderer" style={{ height: this.props.savedHeight }} />;
|
return <div className="renderer-container code-renderer" style={{ height: this.props.savedHeight }} />;
|
||||||
@ -220,7 +234,7 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
<Editor
|
<Editor
|
||||||
theme="hc-black"
|
theme="hc-black"
|
||||||
height={this.state.editorHeight}
|
height={this.state.editorHeight}
|
||||||
defaultLanguage={language}
|
defaultLanguage={selectedLanguage}
|
||||||
defaultValue={code}
|
defaultValue={code}
|
||||||
onMount={this.handleEditorDidMount}
|
onMount={this.handleEditorDidMount}
|
||||||
options={{
|
options={{
|
||||||
@ -228,16 +242,6 @@ class SourceCodeRenderer extends React.Component<
|
|||||||
fontSize: GlobalModel.termFontSize.get(),
|
fontSize: GlobalModel.termFontSize.get(),
|
||||||
fontFamily: "JetBrains Mono",
|
fontFamily: "JetBrains Mono",
|
||||||
readOnly: readOnly || isClosed,
|
readOnly: readOnly || isClosed,
|
||||||
keybindings: [
|
|
||||||
{
|
|
||||||
key: "ctrl+s",
|
|
||||||
command: "-editor.action.filesave",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "cmd+s",
|
|
||||||
command: "-editor.action.filesave",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
}}
|
||||||
onChange={this.handleEditorChange}
|
onChange={this.handleEditorChange}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user