working with monaco anys

This commit is contained in:
Olivier Gagnon 2022-07-19 20:10:30 -04:00
parent 0c07dddb36
commit dfadfe6eb2
3 changed files with 10 additions and 7 deletions

@ -58,7 +58,7 @@ export interface IPlayer extends IPerson {
moneySourceB: MoneySourceTracker; moneySourceB: MoneySourceTracker;
playtimeSinceLastAug: number; playtimeSinceLastAug: number;
playtimeSinceLastBitnode: number; playtimeSinceLastBitnode: number;
purchasedServers: any[]; purchasedServers: string[];
queuedAugmentations: IPlayerOwnedAugmentation[]; queuedAugmentations: IPlayerOwnedAugmentation[];
scriptProdSinceLastAug: number; scriptProdSinceLastAug: number;
sleeves: Sleeve[]; sleeves: Sleeve[];

@ -1,6 +1,7 @@
import React, { useState, useEffect, useRef, useMemo } from "react"; import React, { useState, useEffect, useRef, useMemo } from "react";
import Editor, { Monaco } from "@monaco-editor/react"; import Editor from "@monaco-editor/react";
import * as monaco from "monaco-editor"; import * as monaco from "monaco-editor";
import type { Monaco } from "@monaco-editor/react";
type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor; type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;
type ITextModel = monaco.editor.ITextModel; type ITextModel = monaco.editor.ITextModel;
@ -195,7 +196,6 @@ export function Root(props: IProps): React.ReactElement {
try { try {
// @ts-expect-error // @ts-expect-error
window.require(["monaco-vim"], function (MonacoVim: any) { window.require(["monaco-vim"], function (MonacoVim: any) {
console.log(MonacoVim);
setVimEditor(MonacoVim.initVimMode(editor, vimStatusRef.current)); setVimEditor(MonacoVim.initVimMode(editor, vimStatusRef.current));
MonacoVim.VimMode.Vim.defineEx("write", "w", function () { MonacoVim.VimMode.Vim.defineEx("write", "w", function () {
// your own implementation on what you want to do when :w is pressed // your own implementation on what you want to do when :w is pressed

@ -1,6 +1,9 @@
import * as monaco from "monaco-editor";
import type { Monaco } from "@monaco-editor/react";
export interface IScriptEditorTheme { export interface IScriptEditorTheme {
[key: string]: any; [key: string]: any;
base: string; base: "vs" | "vs-dark" | "hc-black";
inherit: boolean; inherit: boolean;
common: { common: {
[key: string]: string; [key: string]: string;
@ -85,7 +88,7 @@ export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
continue; continue;
} }
const repairBlock = (block: { [key: string]: any }): void => { const repairBlock = (block: { [key: string]: object | string }): void => {
for (const [k, v] of Object.entries(block)) { for (const [k, v] of Object.entries(block)) {
if (typeof v === "object") { if (typeof v === "object") {
repairBlock(v as { [key: string]: string }); repairBlock(v as { [key: string]: string });
@ -96,7 +99,7 @@ export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
} }
}; };
export function makeTheme(theme: IScriptEditorTheme): any { export function makeTheme(theme: IScriptEditorTheme): monaco.editor.IStandaloneThemeData {
const themeRules = [ const themeRules = [
{ {
token: "", token: "",
@ -211,7 +214,7 @@ export function makeTheme(theme: IScriptEditorTheme): any {
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: { editor: any }): Promise<void> { export async function loadThemes(monaco: Monaco): Promise<void> {
monaco.editor.defineTheme("monokai", { monaco.editor.defineTheme("monokai", {
base: "vs-dark", base: "vs-dark",
inherit: true, inherit: true,