mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-03-02 04:02:13 +01:00
fix typescript errors
This commit is contained in:
parent
31f90d5401
commit
b2a1560385
@ -11,3 +11,9 @@ node_modules/.bin/webpack --watch --config webpack.dev.js
|
||||
# @scripthaus cd :current
|
||||
node_modules/.bin/webpack-dev-server --config webpack.dev.js --host 0.0.0.0
|
||||
```
|
||||
|
||||
```bash
|
||||
# @scripthaus command typecheck
|
||||
# @scripthaus cd :current
|
||||
node_modules/.bin/tsc --jsx preserve --noEmit --esModuleInterop --target ES5 --experimentalDecorators --downlevelIteration src/sh2.ts
|
||||
```
|
||||
|
18
src/main.tsx
18
src/main.tsx
@ -3,11 +3,12 @@ import * as mobxReact from "mobx-react";
|
||||
import * as mobx from "mobx";
|
||||
import {sprintf} from "sprintf-js";
|
||||
import {boundMethod} from "autobind-decorator";
|
||||
import * as dayjs from 'dayjs'
|
||||
import dayjs from 'dayjs'
|
||||
import {If, For, When, Otherwise, Choose} from "tsx-control-statements/components";
|
||||
import cn from "classnames"
|
||||
import {TermWrap} from "./term";
|
||||
import {getDefaultSession, getLineId} from "./session";
|
||||
import {getDefaultSession, getLineId, Session} from "./session";
|
||||
import type {LineType} from "./session";
|
||||
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
||||
|
||||
dayjs.extend(localizedFormat)
|
||||
@ -70,7 +71,7 @@ class LineText extends React.Component<{line : LineType, session : Session}, {}>
|
||||
}
|
||||
|
||||
@mobxReact.observer
|
||||
class LineCmd extends React.Component<{line : LineType, session : Session, changeSizeCallback : () => void}, {}> {
|
||||
class LineCmd extends React.Component<{line : LineType, session : Session, changeSizeCallback? : (term : TermWrap) => void}, {}> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
@ -127,7 +128,7 @@ class LineCmd extends React.Component<{line : LineType, session : Session, chang
|
||||
let termSize = termWrap.getSize();
|
||||
let formattedTime = getLineDateStr(line.ts);
|
||||
let cellHeightPx = 17;
|
||||
let totalHeight = cellHeightPx * termWrap.usedRows;
|
||||
let totalHeight = cellHeightPx * termWrap.usedRows.get();
|
||||
return (
|
||||
<div className="line line-cmd" id={"line-" + getLineId(line)}>
|
||||
<div className={cn("avatar",{"num4": lineid.length == 4}, {"num5": lineid.length >= 5}, {"running": running})}>
|
||||
@ -161,7 +162,7 @@ class LineCmd extends React.Component<{line : LineType, session : Session, chang
|
||||
}
|
||||
|
||||
@mobxReact.observer
|
||||
class Line extends React.Component<{line : LineType, session : Session}, {}> {
|
||||
class Line extends React.Component<{line : LineType, session : Session, changeSizeCallback? : (term : TermWrap) => void}, {}> {
|
||||
render() {
|
||||
let line = this.props.line;
|
||||
if (line.linetype == "text") {
|
||||
@ -273,7 +274,7 @@ class CmdInput extends React.Component<{session : Session, windowid : string}, {
|
||||
<div className="button is-static">mike@local</div>
|
||||
</div>
|
||||
<div className="control cmd-input-control is-expanded">
|
||||
<textarea value={curLine} onKeyDown={this.onKeyDown} onChange={this.onChange} className="input" type="text"></textarea>
|
||||
<textarea value={curLine} onKeyDown={this.onKeyDown} onChange={this.onChange} className="input"></textarea>
|
||||
</div>
|
||||
<div className="control cmd-exec">
|
||||
<div onClick={this.doSubmitCmd} className="button">
|
||||
@ -289,8 +290,8 @@ class CmdInput extends React.Component<{session : Session, windowid : string}, {
|
||||
}
|
||||
|
||||
@mobxReact.observer
|
||||
class SessionView extends React.Component<{session : SessionType}, {}> {
|
||||
shouldFollow : IObservableValue<boolean> = mobx.observable.box(true);
|
||||
class SessionView extends React.Component<{session : Session}, {}> {
|
||||
shouldFollow : mobx.IObservableValue<boolean> = mobx.observable.box(true);
|
||||
|
||||
@boundMethod
|
||||
scrollHandler(event : any) {
|
||||
@ -325,6 +326,7 @@ class SessionView extends React.Component<{session : SessionType}, {}> {
|
||||
return <div className="session-view">(loading)</div>;
|
||||
}
|
||||
let idx = 0;
|
||||
let line : LineType = null;
|
||||
return (
|
||||
<div className="session-view">
|
||||
<div className="lines" onScroll={this.scrollHandler}>
|
||||
|
@ -49,7 +49,8 @@ type WindowDataType = {
|
||||
windowid : string,
|
||||
name : string,
|
||||
curremote : string,
|
||||
lines : mobx.IObservableValue<LineType[]>,
|
||||
lines : mobx.IObservableArray<LineType>,
|
||||
linesLoading : mobx.IObservableValue<boolean>,
|
||||
version : number,
|
||||
};
|
||||
|
||||
@ -64,6 +65,9 @@ type SessionDataType = {
|
||||
cmds : CmdDataType[],
|
||||
};
|
||||
|
||||
type CmdDataType = {
|
||||
};
|
||||
|
||||
class Session {
|
||||
sessionId : string;
|
||||
name : string;
|
||||
@ -112,7 +116,7 @@ class Session {
|
||||
}
|
||||
|
||||
getCurWindow() : WindowDataType {
|
||||
return this.getWindowById(this.activeWindowId);
|
||||
return this.getWindowById(this.activeWindowId.get());
|
||||
}
|
||||
|
||||
loadWindowLines(windowid : string) {
|
||||
@ -127,7 +131,7 @@ class Session {
|
||||
window.linesLoading.set(true);
|
||||
|
||||
let usp = new URLSearchParams({sessionid: this.sessionId, windowid: windowid});
|
||||
let url = sprintf("http://localhost:8080/api/get-window-lines?") + usp.toString();
|
||||
let url = new URL(sprintf("http://localhost:8080/api/get-window-lines?") + usp.toString());
|
||||
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||
mobx.action(() => {
|
||||
window.lines.replace(data.data || []);
|
||||
@ -146,15 +150,16 @@ class Session {
|
||||
|
||||
submitCommand(windowid : string, commandStr : string) {
|
||||
let url = sprintf("http://localhost:8080/api/run-command");
|
||||
let data = {type: "fecmd", sessionid: this.sessionId, windowid: windowid, cmdstr: commandStr, userid: GlobalUser};
|
||||
let data = {type: "fecmd", sessionid: this.sessionId, windowid: windowid, cmdstr: commandStr, userid: GlobalUser, remotestate: null};
|
||||
let curWindow = this.getCurWindow();
|
||||
if (curWindow == null) {
|
||||
throw new Error(sprintf("invalid current window=%s", this.activeWindowId));
|
||||
}
|
||||
data.remotestate = this.getWindowCurRemoteData(this.activeWindowId);
|
||||
if (data.remotestate == null) {
|
||||
throw new Error(sprintf("no remotestate found for windowid:%s (remote=%s), cannot submit command", windowid, window.curremote));
|
||||
let rstate = this.getWindowCurRemoteData(this.activeWindowId.get());
|
||||
if (rstate == null) {
|
||||
throw new Error(sprintf("no remotestate found for windowid:%s (remote=%s), cannot submit command", windowid, curWindow.curremote));
|
||||
}
|
||||
data.remotestate = rstate;
|
||||
fetch(url, {method: "post", body: JSON.stringify(data)}).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||
mobx.action(() => {
|
||||
if (data.data != null && data.data.line != null) {
|
||||
@ -280,7 +285,7 @@ function initSession() {
|
||||
});
|
||||
|
||||
let usp = new URLSearchParams({name: "default"});
|
||||
let url = sprintf("http://localhost:8080/api/get-session?") + usp.toString();
|
||||
let url = new URL(sprintf("http://localhost:8080/api/get-session?") + usp.toString());
|
||||
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||
mobx.action(() => {
|
||||
let sdata = data.data;
|
||||
@ -307,7 +312,7 @@ function getDefaultSession() : Session {
|
||||
return DefaultSession;
|
||||
}
|
||||
|
||||
window.getDefaultSession = getDefaultSession;
|
||||
(window as any).getDefaultSession = getDefaultSession;
|
||||
|
||||
export {Session, getDefaultSession, getLineId, initSession};
|
||||
export type {LineType, WindowDataType};
|
||||
|
@ -7,9 +7,10 @@ import {GlobalWS} from "./ws";
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import {initSession} from "./session";
|
||||
|
||||
// @ts-ignore
|
||||
let VERSION = __SHVERSION__;
|
||||
|
||||
window.ScriptHausClientId = uuidv4();
|
||||
(window as any).ScriptHausClientId = uuidv4();
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
initSession();
|
||||
|
12
src/term.ts
12
src/term.ts
@ -19,7 +19,7 @@ function loadPtyOut(term : Terminal, sessionId : string, cmdId : string, delayMs
|
||||
}
|
||||
|
||||
class TermWrap {
|
||||
terminal : Terminal;
|
||||
terminal : any;
|
||||
termId : string;
|
||||
sessionId : string;
|
||||
cmdId : string;
|
||||
@ -33,7 +33,7 @@ class TermWrap {
|
||||
atRowMax : boolean = false;
|
||||
initialized : boolean = false;
|
||||
changeSizeCallback : (TermWrap) => void = null;
|
||||
usedRows : number = null;
|
||||
usedRows : mobx.IObservableValue<number> = null;
|
||||
|
||||
constructor(sessionId : string, cmdId : string) {
|
||||
this.termId = uuidv4();
|
||||
@ -109,7 +109,7 @@ class TermWrap {
|
||||
usedRows = i+1;
|
||||
}
|
||||
}
|
||||
this.usedRows = usedRows;
|
||||
this.usedRows.set(usedRows);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -117,11 +117,11 @@ class TermWrap {
|
||||
this.flexRows = true;
|
||||
this.maxRows = rows;
|
||||
if (!flexRows) {
|
||||
term.resize(rows, cols);
|
||||
setTimeout(() => incRenderVersion(), 10);
|
||||
this.terminal.resize(rows, cols);
|
||||
setTimeout(() => this.incRenderVersion(), 10);
|
||||
return;
|
||||
}
|
||||
resizeToContent();
|
||||
this.resizeToContent();
|
||||
}
|
||||
|
||||
getSize() : {rows : number, cols : number} {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import {sprintf} from "sprintf-js";
|
||||
|
||||
function fetchJsonData(resp : any, ctErr : boolean) : Promise<any> {
|
||||
let contentType = resp.headers.get("Content-Type");
|
||||
if (contentType != null && contentType.startsWith("application/json")) {
|
||||
|
@ -2,11 +2,13 @@ import * as mobx from "mobx";
|
||||
import {sprintf} from "sprintf-js";
|
||||
import {boundMethod} from "autobind-decorator";
|
||||
|
||||
declare var window : any;
|
||||
|
||||
class WSControl {
|
||||
wsConn : any;
|
||||
open : mobx.IObservableValue<boolean>;
|
||||
opening : boolean = false;
|
||||
reconnectTimes : int = 0;
|
||||
reconnectTimes : number = 0;
|
||||
msgQueue : any[] = [];
|
||||
reqMap : Record<string, (dataPacket : any) => void> = {};
|
||||
|
||||
@ -109,7 +111,7 @@ class WSControl {
|
||||
return;
|
||||
}
|
||||
if (eventData.type == "ping") {
|
||||
this.wsConn.send(JSON.stringify({type: "pong", stime: parseInt(Date.now()/1000)}));
|
||||
this.wsConn.send(JSON.stringify({type: "pong", stime: Date.now()}));
|
||||
return;
|
||||
}
|
||||
if (eventData.type == "pong") {
|
||||
|
Loading…
Reference in New Issue
Block a user