import React from "react"; import * as monaco from "monaco-editor"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import Link from "@mui/material/Link"; import Table from "@mui/material/Table"; import TableCell from "@mui/material/TableCell"; import TableRow from "@mui/material/TableRow"; import TableBody from "@mui/material/TableBody"; import Typography from "@mui/material/Typography"; import SettingsIcon from "@mui/icons-material/Settings"; import { makeTheme, sanitizeTheme } from "./themes"; import { CONSTANTS } from "../../Constants"; import { Modal } from "../../ui/React/Modal"; import { Page } from "../../ui/Router"; import { Router } from "../../ui/GameRoot"; import { useBoolean } from "../../ui/React/hooks"; import { Settings } from "../../Settings/Settings"; import { OptionsModal, OptionsModalProps } from "./OptionsModal"; import { useScriptEditorContext } from "./ScriptEditorContext"; const docUrl = "https://github.com/bitburner-official/bitburner-src/blob/" + (CONSTANTS.isDevBranch ? "dev" : "stable") + "/markdown/bitburner.ns.md"; type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor; interface IProps { editor: IStandaloneCodeEditor | null; onSave: () => void; } export function Toolbar({ editor, onSave }: IProps) { const [ramInfoOpen, { on: openRAMInfo, off: closeRAMInfo }] = useBoolean(false); const [optionsOpen, { on: openOptions, off: closeOptions }] = useBoolean(false); function beautify(): void { editor?.getAction("editor.action.formatDocument")?.run(); } const { ram, ramEntries, isUpdatingRAM, options, saveOptions } = useScriptEditorContext(); const onOptionChange: OptionsModalProps["onOptionChange"] = (option, value) => { const newOptions = { ...options, [option]: value }; saveOptions(newOptions); // delaying editor options update to avoid an issue // where switching between vim and regular modes causes some settings to be reset setTimeout(() => { editor?.updateOptions(newOptions); }, 100); }; const onThemeChange = () => { sanitizeTheme(Settings.EditorTheme); monaco.editor.defineTheme("customTheme", makeTheme(Settings.EditorTheme)); }; return ( <> Documentation {ramEntries.map(([n, r]) => ( {n} {r} ))}
); }