CODEBASE: Validate theme, editor theme, and styles (#1789)

This commit is contained in:
catloversg
2025-01-09 10:20:05 +07:00
committed by GitHub
parent 320c852386
commit 0f9144a059
27 changed files with 969 additions and 213 deletions
+9 -11
View File
@@ -12,6 +12,7 @@ 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;
@@ -74,21 +75,18 @@ export function ThemeEditorModal(props: ThemeEditorProps): React.ReactElement {
}
function onThemeChange(event: React.ChangeEvent<HTMLInputElement>): void {
let themeData: unknown;
try {
const importedTheme = JSON.parse(event.target.value) as typeof Settings.EditorTheme;
if (importedTheme == null) {
throw new Error("Theme data must not be null or undefined.");
}
if (typeof importedTheme !== "object") {
throw new Error(`Theme data is invalid.`);
}
Settings.EditorTheme = importedTheme;
props.onChange();
themeData = JSON.parse(event.target.value);
assertAndSanitizeEditorTheme(themeData);
} catch (error) {
console.error(`Theme data is invalid. Data: ${event.target.value}.`);
console.error(error);
dialogBoxCreate(`Invalid theme. ${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 = () => {