From 85f22a07334558b2b491da35c8e68a68b275bbfc Mon Sep 17 00:00:00 2001 From: Red J Adaya Date: Tue, 13 Feb 2024 08:39:29 +0800 Subject: [PATCH] Declare types as global (#282) * declare types as global * remove mobx types aliases * put back model_old.ts * remove types.ts --- src/app/app.tsx | 3 - src/app/appconst.ts | 10 + src/app/bookmarks/bookmarks.tsx | 1 - src/app/clientsettings/clientsettings.tsx | 11 +- .../elements/inlinesettingstextedit.tsx | 2 - src/app/common/elements/modal.tsx | 2 - src/app/common/elements/resizablesidebar.tsx | 2 - src/app/common/elements/settingserror.tsx | 2 - src/app/common/error/errorboundary.tsx | 1 - src/app/common/icons/icons.tsx | 12 +- src/app/common/modals/createremoteconn.tsx | 5 +- src/app/common/modals/editremoteconn.tsx | 7 +- src/app/common/modals/linesettings.tsx | 3 - src/app/common/modals/screensettings.tsx | 3 - src/app/common/modals/sessionsettings.tsx | 2 - src/app/common/modals/tabswitcher.tsx | 3 - src/app/common/modals/tos.tsx | 1 - src/app/common/modals/userinput.tsx | 1 - .../common/modals/viewremoteconndetail.tsx | 13 +- src/app/common/prompt/prompt.tsx | 25 - src/app/connections/connections.tsx | 10 +- src/app/history/history.tsx | 10 - src/app/line/linecomps.tsx | 12 - src/app/line/linesview.tsx | 20 +- src/app/line/lineutil.ts | 1 - src/app/line/renderer/basicrenderer.tsx | 24 +- src/app/sidebar/sidebar.tsx | 1 - src/app/workspace/cmdinput/aichat.tsx | 5 +- src/app/workspace/cmdinput/cmdinput.tsx | 1 - src/app/workspace/cmdinput/historyinfo.tsx | 1 - src/app/workspace/cmdinput/textareainput.tsx | 5 +- src/app/workspace/screen/screenview.tsx | 12 +- src/app/workspace/workspaceview.tsx | 2 - src/models/bookmarks.ts | 2 - src/models/cmd.ts | 10 - src/models/commandrunner.ts | 1 - src/models/forwardlinecontainer.ts | 31 +- src/models/historyview.ts | 9 - src/models/input.ts | 11 - src/models/mainsidebar.ts | 2 +- src/models/modals.ts | 2 - src/models/model.ts | 37 - src/models/plugins.ts | 3 - src/models/remotes.ts | 2 - src/models/screen.ts | 23 +- src/models/screenlines.ts | 2 - src/models/session.ts | 2 - src/models/speciallinecontainer.ts | 1 - src/models/ws.ts | 1 - src/plugins/code/code.tsx | 11 +- src/plugins/core/basicrenderer.tsx | 25 +- src/plugins/core/incrementalrenderer.tsx | 12 +- src/plugins/core/ptydata.ts | 4 - src/plugins/csv/csv.tsx | 12 +- src/plugins/image/image.tsx | 6 +- src/plugins/markdown/markdown.tsx | 11 +- src/plugins/mustache/mustache.tsx | 11 +- src/plugins/openai/openai.tsx | 21 +- src/plugins/plugins.ts | 1 - src/plugins/terminal/term.ts | 9 - src/plugins/terminal/terminal.tsx | 5 - src/types/custom.d.ts | 815 +++++++++++++++++- src/util/modelutil.ts | 1 - src/util/util.ts | 3 - 64 files changed, 914 insertions(+), 385 deletions(-) diff --git a/src/app/app.tsx b/src/app/app.tsx index 2d11394c..bd626a78 100644 --- a/src/app/app.tsx +++ b/src/app/app.tsx @@ -7,7 +7,6 @@ import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; import { If } from "tsx-control-statements/components"; import dayjs from "dayjs"; -import type { ContextMenuOpts } from "../types/types"; import localizedFormat from "dayjs/plugin/localizedFormat"; import { GlobalModel } from "../models"; import { isBlank } from "../util/util"; @@ -25,8 +24,6 @@ import "./app.less"; dayjs.extend(localizedFormat); -type OV = mobx.IObservableValue; - @mobxReact.observer class App extends React.Component<{}, {}> { dcWait: OV = mobx.observable.box(false, { name: "dcWait" }); diff --git a/src/app/appconst.ts b/src/app/appconst.ts index 24e177e1..74233180 100644 --- a/src/app/appconst.ts +++ b/src/app/appconst.ts @@ -47,3 +47,13 @@ export const TabIcons = [ export const VERSION = __WAVETERM_VERSION__; // @ts-ignore export const BUILD = __WAVETERM_BUILD__; + +/** + * Levels for the screen status indicator + */ +export enum StatusIndicatorLevel { + None = 0, + Output = 1, + Success = 2, + Error = 3, +} diff --git a/src/app/bookmarks/bookmarks.tsx b/src/app/bookmarks/bookmarks.tsx index 6809ff3b..d86d13c1 100644 --- a/src/app/bookmarks/bookmarks.tsx +++ b/src/app/bookmarks/bookmarks.tsx @@ -7,7 +7,6 @@ import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; import { If, For } from "tsx-control-statements/components"; import cn from "classnames"; -import type { BookmarkType } from "../../types/types"; import { GlobalModel } from "../../models"; import { CmdStrCode, Markdown } from "../common/elements"; diff --git a/src/app/clientsettings/clientsettings.tsx b/src/app/clientsettings/clientsettings.tsx index 3786e594..2024c054 100644 --- a/src/app/clientsettings/clientsettings.tsx +++ b/src/app/clientsettings/clientsettings.tsx @@ -8,7 +8,6 @@ import { boundMethod } from "autobind-decorator"; import cn from "classnames"; import { GlobalModel, GlobalCommandRunner, RemotesModel } from "../../models"; import { Toggle, InlineSettingsTextEdit, SettingsError, Dropdown } from "../common/elements"; -import * as types from "../../types/types"; import { commandRtnHandler, isBlank } from "../../util/util"; import * as appconst from "../appconst"; @@ -16,10 +15,10 @@ import "./clientsettings.less"; @mobxReact.observer class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hoveredItemId: string }> { - fontSizeDropdownActive: types.OV = mobx.observable.box(false, { + fontSizeDropdownActive: OV = mobx.observable.box(false, { name: "clientSettings-fontSizeDropdownActive", }); - errorMessage: types.OV = mobx.observable.box(null, { name: "ClientSettings-errorMessage" }); + errorMessage: OV = mobx.observable.box(null, { name: "ClientSettings-errorMessage" }); @boundMethod dismissError(): void { @@ -48,7 +47,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove @boundMethod handleChangeTelemetry(val: boolean): void { - let prtn: Promise = null; + let prtn: Promise = null; if (val) { prtn = GlobalCommandRunner.telemetryOn(false); } else { @@ -59,7 +58,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove @boundMethod handleChangeReleaseCheck(val: boolean): void { - let prtn: Promise = null; + let prtn: Promise = null; if (val) { prtn = GlobalCommandRunner.releaseCheckAutoOn(false); } else { @@ -112,7 +111,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove return null; } - let cdata: types.ClientDataType = GlobalModel.clientData.get(); + let cdata: ClientDataType = GlobalModel.clientData.get(); let openAIOpts = cdata.openaiopts ?? {}; let apiTokenStr = isBlank(openAIOpts.apitoken) ? "(not set)" : "********"; let maxTokensStr = String( diff --git a/src/app/common/elements/inlinesettingstextedit.tsx b/src/app/common/elements/inlinesettingstextedit.tsx index 194eeead..ed2b6277 100644 --- a/src/app/common/elements/inlinesettingstextedit.tsx +++ b/src/app/common/elements/inlinesettingstextedit.tsx @@ -11,8 +11,6 @@ import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "../../../util/k import "./inlinesettingstextedit.less"; -type OV = mobx.IObservableValue; - @mobxReact.observer class InlineSettingsTextEdit extends React.Component< { diff --git a/src/app/common/elements/modal.tsx b/src/app/common/elements/modal.tsx index cc8c1ff8..f05d27c2 100644 --- a/src/app/common/elements/modal.tsx +++ b/src/app/common/elements/modal.tsx @@ -10,8 +10,6 @@ import { IconButton } from "./iconbutton"; import "./modal.less"; -type OV = mobx.IObservableValue; - interface ModalHeaderProps { onClose?: () => void; title: string; diff --git a/src/app/common/elements/resizablesidebar.tsx b/src/app/common/elements/resizablesidebar.tsx index e34f7424..29806ce1 100644 --- a/src/app/common/elements/resizablesidebar.tsx +++ b/src/app/common/elements/resizablesidebar.tsx @@ -11,8 +11,6 @@ import { MagicLayout } from "../../magiclayout"; import "./resizablesidebar.less"; -type OV = mobx.IObservableValue; - interface ResizableSidebarProps { parentRef: React.RefObject; position: "left" | "right"; diff --git a/src/app/common/elements/settingserror.tsx b/src/app/common/elements/settingserror.tsx index aa72b836..e2296b13 100644 --- a/src/app/common/elements/settingserror.tsx +++ b/src/app/common/elements/settingserror.tsx @@ -6,8 +6,6 @@ import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; -type OV = mobx.IObservableValue; - @mobxReact.observer class SettingsError extends React.Component<{ errorMessage: OV }, {}> { @boundMethod diff --git a/src/app/common/error/errorboundary.tsx b/src/app/common/error/errorboundary.tsx index d4d32a7b..6b1e15d3 100644 --- a/src/app/common/error/errorboundary.tsx +++ b/src/app/common/error/errorboundary.tsx @@ -1,5 +1,4 @@ import React, { Component, ReactNode } from "react"; -import { RendererContext } from "../../../types/types"; import cn from "classnames"; interface ErrorBoundaryState { diff --git a/src/app/common/icons/icons.tsx b/src/app/common/icons/icons.tsx index e437b044..a24cf673 100644 --- a/src/app/common/icons/icons.tsx +++ b/src/app/common/icons/icons.tsx @@ -1,10 +1,10 @@ import React from "react"; -import { StatusIndicatorLevel } from "../../../types/types"; import cn from "classnames"; import { ReactComponent as SpinnerIndicator } from "../../assets/icons/spinner-indicator.svg"; import { boundMethod } from "autobind-decorator"; import * as mobx from "mobx"; import * as mobxReact from "mobx-react"; +import * as appconst from "../../appconst"; import { ReactComponent as RotateIconSvg } from "../../assets/icons/line/rotate.svg"; @@ -131,7 +131,7 @@ interface StatusIndicatorProps { /** * The level of the status indicator. This will determine the color of the status indicator. */ - level: StatusIndicatorLevel; + level: appconst.StatusIndicatorLevel; className?: string; /** * If true, a spinner will be shown around the status indicator. @@ -191,16 +191,16 @@ export class StatusIndicator extends React.Component { const { level, className, runningCommands } = this.props; const spinnerVisible = this.spinnerVisible.get(); let statusIndicator = null; - if (level != StatusIndicatorLevel.None || spinnerVisible) { + if (level != appconst.StatusIndicatorLevel.None || spinnerVisible) { let indicatorLevelClass = null; switch (level) { - case StatusIndicatorLevel.Output: + case appconst.StatusIndicatorLevel.Output: indicatorLevelClass = "output"; break; - case StatusIndicatorLevel.Success: + case appconst.StatusIndicatorLevel.Success: indicatorLevelClass = "success"; break; - case StatusIndicatorLevel.Error: + case appconst.StatusIndicatorLevel.Error: indicatorLevelClass = "error"; break; } diff --git a/src/app/common/modals/createremoteconn.tsx b/src/app/common/modals/createremoteconn.tsx index 08cb18ec..019832b2 100644 --- a/src/app/common/modals/createremoteconn.tsx +++ b/src/app/common/modals/createremoteconn.tsx @@ -7,7 +7,6 @@ import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; import { If } from "tsx-control-statements/components"; import { GlobalModel, GlobalCommandRunner, RemotesModel } from "../../../models"; -import * as T from "../../../types/types"; import { Modal, TextField, @@ -22,8 +21,6 @@ import * as util from "../../../util/util"; import "./createremoteconn.less"; -type OV = mobx.IObservableValue; - @mobxReact.observer class CreateRemoteConnModal extends React.Component<{}, {}> { tempAlias: OV; @@ -35,7 +32,7 @@ class CreateRemoteConnModal extends React.Component<{}, {}> { tempKeyFile: OV; tempShellPref: OV; errorStr: OV; - remoteEdit: T.RemoteEditType; + remoteEdit: RemoteEditType; model: RemotesModel; constructor(props: { remotesModel?: RemotesModel }) { diff --git a/src/app/common/modals/editremoteconn.tsx b/src/app/common/modals/editremoteconn.tsx index 3184de61..9752755b 100644 --- a/src/app/common/modals/editremoteconn.tsx +++ b/src/app/common/modals/editremoteconn.tsx @@ -7,14 +7,11 @@ import * as mobx from "mobx"; import { If } from "tsx-control-statements/components"; import { boundMethod } from "autobind-decorator"; import { GlobalModel, GlobalCommandRunner, RemotesModel } from "../../../models"; -import * as T from "../../../types/types"; import { Modal, TextField, InputDecoration, Dropdown, PasswordField, Tooltip } from "../elements"; import * as util from "../../../util/util"; import "./editremoteconn.less"; -type OV = mobx.IObservableValue; - const PasswordUnchangedSentinel = "--unchanged--"; @mobxReact.observer @@ -42,11 +39,11 @@ class EditRemoteConnModal extends React.Component<{}, {}> { return this.model.selectedRemoteId.get(); } - get selectedRemote(): T.RemoteType { + get selectedRemote(): RemoteType { return GlobalModel.getRemote(this.selectedRemoteId); } - get remoteEdit(): T.RemoteEditType { + get remoteEdit(): RemoteEditType { return this.model.remoteEdit.get(); } diff --git a/src/app/common/modals/linesettings.tsx b/src/app/common/modals/linesettings.tsx index 8ce648b2..32a6e7d0 100644 --- a/src/app/common/modals/linesettings.tsx +++ b/src/app/common/modals/linesettings.tsx @@ -7,14 +7,11 @@ import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; import { GlobalModel, GlobalCommandRunner } from "../../../models"; import { SettingsError, Modal, Dropdown } from "../elements"; -import { LineType, RendererPluginType } from "../../../types/types"; import { PluginModel } from "../../../plugins/plugins"; import { commandRtnHandler } from "../../../util/util"; import "./linesettings.less"; -type OV = mobx.IObservableValue; - @mobxReact.observer class LineSettingsModal extends React.Component<{}, {}> { rendererDropdownActive: OV = mobx.observable.box(false, { name: "lineSettings-rendererDropdownActive" }); diff --git a/src/app/common/modals/screensettings.tsx b/src/app/common/modals/screensettings.tsx index 3f657fc7..792d10b8 100644 --- a/src/app/common/modals/screensettings.tsx +++ b/src/app/common/modals/screensettings.tsx @@ -9,7 +9,6 @@ import { If, For } from "tsx-control-statements/components"; import cn from "classnames"; import { GlobalModel, GlobalCommandRunner, Screen } from "../../../models"; import { Toggle, InlineSettingsTextEdit, SettingsError, Modal, Dropdown, Tooltip } from "../elements"; -import { RemoteType } from "../../../types/types"; import * as util from "../../../util/util"; import { commandRtnHandler } from "../../../util/util"; import { ReactComponent as SquareIcon } from "../../assets/icons/tab/square.svg"; @@ -19,8 +18,6 @@ import * as appconst from "../../appconst"; import "./screensettings.less"; -type OV = mobx.IObservableValue; - const ScreenDeleteMessage = ` Are you sure you want to delete this tab? diff --git a/src/app/common/modals/sessionsettings.tsx b/src/app/common/modals/sessionsettings.tsx index e0be3f09..ffc09798 100644 --- a/src/app/common/modals/sessionsettings.tsx +++ b/src/app/common/modals/sessionsettings.tsx @@ -12,8 +12,6 @@ import { commandRtnHandler } from "../../../util/util"; import "./sessionsettings.less"; -type OV = mobx.IObservableValue; - const SessionDeleteMessage = ` Are you sure you want to delete this workspace? diff --git a/src/app/common/modals/tabswitcher.tsx b/src/app/common/modals/tabswitcher.tsx index 5a4b213e..b45057bb 100644 --- a/src/app/common/modals/tabswitcher.tsx +++ b/src/app/common/modals/tabswitcher.tsx @@ -15,9 +15,6 @@ import { ReactComponent as SquareIcon } from "../../assets/icons/tab/square.svg" import "./tabswitcher.less"; -type OV = mobx.IObservableValue; -type OArr = mobx.IObservableArray; - type SwitcherDataType = { sessionId: string; sessionName: string; diff --git a/src/app/common/modals/tos.tsx b/src/app/common/modals/tos.tsx index 3ef78cbf..b6c04ece 100644 --- a/src/app/common/modals/tos.tsx +++ b/src/app/common/modals/tos.tsx @@ -7,7 +7,6 @@ import { boundMethod } from "autobind-decorator"; import { GlobalModel, GlobalCommandRunner } from "../../../models"; import { Toggle, Modal, Button } from "../elements"; import * as util from "../../../util/util"; -import { ClientDataType } from "../../../types/types"; import shield from "../../assets/icons/shield_check.svg"; import help from "../../assets/icons/help_filled.svg"; diff --git a/src/app/common/modals/userinput.tsx b/src/app/common/modals/userinput.tsx index b431043e..436a63c2 100644 --- a/src/app/common/modals/userinput.tsx +++ b/src/app/common/modals/userinput.tsx @@ -2,7 +2,6 @@ import * as React from "react"; import { GlobalModel } from "../../../models"; import { Choose, When, If } from "tsx-control-statements/components"; import { Modal, PasswordField, Markdown } from "../elements"; -import { UserInputRequest } from "../../../types/types"; import "./userinput.less"; diff --git a/src/app/common/modals/viewremoteconndetail.tsx b/src/app/common/modals/viewremoteconndetail.tsx index 933f293e..662dd5d7 100644 --- a/src/app/common/modals/viewremoteconndetail.tsx +++ b/src/app/common/modals/viewremoteconndetail.tsx @@ -8,7 +8,6 @@ import { boundMethod } from "autobind-decorator"; import { If, For } from "tsx-control-statements/components"; import cn from "classnames"; import { GlobalModel, GlobalCommandRunner, RemotesModel } from "../../../models"; -import * as T from "../../../types/types"; import { Modal, Tooltip, Button, Status } from "../elements"; import * as util from "../../../util/util"; import * as textmeasure from "../../../util/textmeasure"; @@ -27,7 +26,7 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> { } @mobx.computed - getSelectedRemote(): T.RemoteType { + getSelectedRemote(): RemoteType { const selectedRemoteId = this.model.selectedRemoteId.get(); return GlobalModel.getRemote(selectedRemoteId); } @@ -58,7 +57,7 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> { } } - getRemoteTypeStr(remote: T.RemoteType): string { + getRemoteTypeStr(remote: RemoteType): string { if (!util.isBlank(remote.uname)) { let unameStr = remote.uname; unameStr = unameStr.replace("|", ", "); @@ -136,7 +135,7 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> { this.model.setRecentConnAdded(false); } - renderInstallStatus(remote: T.RemoteType): any { + renderInstallStatus(remote: RemoteType): any { let statusStr: string = null; if (remote.installstatus == "disconnected") { if (remote.needsmshellupgrade) { @@ -160,7 +159,7 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> { ); } - renderHeaderBtns(remote: T.RemoteType): React.ReactNode { + renderHeaderBtns(remote: RemoteType): React.ReactNode { let buttons: React.ReactNode[] = []; const disconnectButton = (