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