Also reduce unnecessary imports
This commit is contained in:
omuretsu 2023-05-16 11:41:55 -04:00
parent 00522fb8f3
commit 27a6b619eb
3 changed files with 11 additions and 14 deletions

@ -2,8 +2,6 @@ import * as monaco from "monaco-editor";
import * as React from "react"; import * as React from "react";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
export type Monaco = typeof monaco;
interface EditorProps { interface EditorProps {
/** Editor options */ /** Editor options */
options: monaco.editor.IEditorOptions; options: monaco.editor.IEditorOptions;

@ -1,11 +1,10 @@
import React, { useState, useEffect, useRef } from "react"; import React, { useState, useEffect, useRef } from "react";
import { Editor, Monaco } from "./Editor"; import { Editor } from "./Editor";
import * as monaco from "monaco-editor"; import * as monaco from "monaco-editor";
// @ts-expect-error This library does not have types. // @ts-expect-error This library does not have types.
import * as MonacoVim from "monaco-vim"; import * as MonacoVim from "monaco-vim";
type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor; type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;
type EditorDecorations = monaco.editor.IEditorDecorationsCollection;
type ITextModel = monaco.editor.ITextModel; type ITextModel = monaco.editor.ITextModel;
import { OptionsModal } from "./OptionsModal"; import { OptionsModal } from "./OptionsModal";
import { Options } from "./Options"; import { Options } from "./Options";
@ -321,7 +320,7 @@ export function Root(props: IProps): React.ReactElement {
const source = (libSource + "").replace(/export /g, ""); const source = (libSource + "").replace(/export /g, "");
monaco.languages.typescript.javascriptDefaults.addExtraLib(source, "netscript.d.ts"); monaco.languages.typescript.javascriptDefaults.addExtraLib(source, "netscript.d.ts");
monaco.languages.typescript.typescriptDefaults.addExtraLib(source, "netscript.d.ts"); monaco.languages.typescript.typescriptDefaults.addExtraLib(source, "netscript.d.ts");
loadThemes(monaco); loadThemes(monaco.editor.defineTheme);
sanitizeTheme(Settings.EditorTheme); sanitizeTheme(Settings.EditorTheme);
monaco.editor.defineTheme("customTheme", makeTheme(Settings.EditorTheme)); monaco.editor.defineTheme("customTheme", makeTheme(Settings.EditorTheme));
} }

@ -1,5 +1,5 @@
import * as monaco from "monaco-editor"; import type { editor } from "monaco-editor";
import type { Monaco } from "./Editor"; type DefineThemeFn = typeof editor.defineTheme;
export interface IScriptEditorTheme { export interface IScriptEditorTheme {
base: "vs" | "vs-dark" | "hc-black"; base: "vs" | "vs-dark" | "hc-black";
@ -93,7 +93,7 @@ export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
} }
}; };
export function makeTheme(theme: IScriptEditorTheme): monaco.editor.IStandaloneThemeData { export function makeTheme(theme: IScriptEditorTheme): editor.IStandaloneThemeData {
const themeRules = [ const themeRules = [
{ {
token: "", token: "",
@ -208,8 +208,8 @@ export function makeTheme(theme: IScriptEditorTheme): monaco.editor.IStandaloneT
return { base: theme.base, inherit: theme.inherit, rules: themeRules, colors: themeColors }; return { base: theme.base, inherit: theme.inherit, rules: themeRules, colors: themeColors };
} }
export async function loadThemes(monaco: Monaco): Promise<void> { export async function loadThemes(defineTheme: DefineThemeFn): Promise<void> {
monaco.editor.defineTheme("monokai", { defineTheme("monokai", {
base: "vs-dark", base: "vs-dark",
inherit: true, inherit: true,
rules: [ rules: [
@ -274,7 +274,7 @@ export async function loadThemes(monaco: Monaco): Promise<void> {
}, },
}); });
monaco.editor.defineTheme("solarized-dark", { defineTheme("solarized-dark", {
base: "vs-dark", base: "vs-dark",
inherit: true, inherit: true,
rules: [ rules: [
@ -351,7 +351,7 @@ export async function loadThemes(monaco: Monaco): Promise<void> {
}, },
}); });
monaco.editor.defineTheme("solarized-light", { defineTheme("solarized-light", {
base: "vs", base: "vs",
inherit: true, inherit: true,
rules: [ rules: [
@ -429,7 +429,7 @@ export async function loadThemes(monaco: Monaco): Promise<void> {
}, },
}); });
monaco.editor.defineTheme("dracula", { defineTheme("dracula", {
base: "vs-dark", base: "vs-dark",
inherit: true, inherit: true,
rules: [ rules: [
@ -525,7 +525,7 @@ export async function loadThemes(monaco: Monaco): Promise<void> {
}, },
}); });
monaco.editor.defineTheme("one-dark", { defineTheme("one-dark", {
base: "vs-dark", base: "vs-dark",
inherit: true, inherit: true,
rules: [ rules: [