import React from "react"; import _ from "lodash"; import { Grid, Box, Button, IconButton, Paper, TextField, Tooltip, Typography } from "@mui/material"; import { History, Reply } from "@mui/icons-material"; import { Color, ColorPicker } from "material-ui-color"; import { Settings } from "../../Settings/Settings"; import { useRerender } from "../../ui/React/hooks"; import { Modal } from "../../ui/React/Modal"; import { OptionSwitch } from "../../ui/React/OptionSwitch"; import { defaultMonacoTheme } from "./themes"; import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { assertAndSanitizeEditorTheme } from "../../JsonSchema/JSONSchemaAssertion"; type ColorEditorProps = { label: string; themePath: string; color: string | undefined; onColorChange: (name: string, value: string) => void; defaultColor: string; }; // Slightly tweaked version of the same function found in game options function ColorEditor({ label, themePath, onColorChange, color, defaultColor }: ColorEditorProps): React.ReactElement { if (color === undefined) { console.error(`color ${themePath} was undefined, reverting to default`); color = defaultColor; } return ( onColorChange(themePath, newColor.hex)} disableAlpha /> ), endAdornment: ( onColorChange(themePath, defaultColor)}> ), }} /> ); } type ThemeEditorProps = { onClose: () => void; onChange: () => void; open: boolean; }; export function ThemeEditorModal(props: ThemeEditorProps): React.ReactElement { const rerender = useRerender(); function onThemePropChange(prop: string, value: string): void { _.set(Settings.EditorTheme, prop, value); props.onChange(); rerender(); } function onThemeChange(event: React.ChangeEvent): void { let themeData: unknown; try { themeData = JSON.parse(event.target.value); assertAndSanitizeEditorTheme(themeData); } catch (error) { console.error(error); console.error("Theme data is invalid. Data:", event.target.value); dialogBoxCreate(`Invalid theme. Errors: ${error}.`); return; } Object.assign(Settings.EditorTheme, themeData); props.onChange(); } const onResetToDefault = () => { Settings.EditorTheme = defaultMonacoTheme; props.onChange(); rerender(); }; return ( Customize Editor theme Hover over input boxes for more information { onThemePropChange("base", val ? "vs" : "vs-dark"); }} text="Use light theme as base" tooltip={ <> If enabled, the vs light theme will be used as the theme base, otherwise,{" "} vs-dark will be used. } /> UI Syntax ); }