chore: remove meta-json-schema #5656 #5478

This commit is contained in:
Slinetrac
2025-11-29 15:10:41 +08:00
parent 1d41cf691b
commit 45d4f0e89c
7 changed files with 4 additions and 59 deletions
+4 -31
View File
@@ -16,9 +16,6 @@ import {
} from "@mui/material";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { useLockFn } from "ahooks";
import { type JSONSchema7 } from "json-schema";
import mergeSchema from "meta-json-schema/schemas/clash-verge-merge-json-schema.json";
import metaSchema from "meta-json-schema/schemas/meta-json-schema.json";
import * as monaco from "monaco-editor";
import { configureMonacoYaml } from "monaco-yaml";
import { nanoid } from "nanoid";
@@ -34,12 +31,6 @@ import getSystem from "@/utils/get-system";
const appWindow = getCurrentWebviewWindow();
type Language = "yaml" | "javascript" | "css";
type Schema<T extends Language> = LanguageSchemaMap[T];
interface LanguageSchemaMap {
yaml: "clash" | "merge";
javascript: never;
css: never;
}
interface Props<T extends Language> {
open: boolean;
@@ -47,11 +38,10 @@ interface Props<T extends Language> {
// Initial content loader: prefer passing a stable function. A plain Promise is supported,
// but it won't trigger background refreshes and should be paired with a stable `dataKey`.
initialData: Promise<string> | (() => Promise<string>);
// Logical document id; reloads when this or language/schema changes.
// Logical document id; reloads when this or language changes.
dataKey?: string | number;
readOnly?: boolean;
language: T;
schema?: Schema<T>;
onChange?: (prev?: string, curr?: string) => void;
onSave?: (prev?: string, curr?: string) => void | Promise<void>;
onClose: () => void;
@@ -61,24 +51,10 @@ let initialized = false;
const monacoInitialization = () => {
if (initialized) return;
// YAML worker and schemas
// YAML worker setup
configureMonacoYaml(monaco, {
validate: true,
enableSchemaRequest: true,
schemas: [
{
uri: "http://example.com/meta-json-schema.json",
fileMatch: ["**/*.clash.yaml"],
// @ts-expect-error -- meta schema JSON import does not satisfy JSONSchema7 at compile time
schema: metaSchema as JSONSchema7,
},
{
uri: "http://example.com/clash-verge-merge-json-schema.json",
fileMatch: ["**/*.merge.yaml"],
// @ts-expect-error -- merge schema JSON import does not satisfy JSONSchema7 at compile time
schema: mergeSchema as JSONSchema7,
},
],
});
// PAC type definitions for JS suggestions
monaco.typescript.javascriptDefaults.addExtraLib(pac, "pac.d.ts");
@@ -98,7 +74,6 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
dataKey,
readOnly = false,
language = "yaml",
schema,
onChange,
onSave,
onClose,
@@ -261,9 +236,8 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
currData.current = data;
setInitialText(data);
// Build a path that matches YAML schemas when applicable, and avoids "undefined" in name
// Build a stable model path and avoid "undefined" in the name
const pathParts = [String(dataKey ?? nanoid()), instanceIdRef.current];
if (schema) pathParts.push(String(schema));
pathParts.push(language);
setModelPath(pathParts.join("."));
@@ -282,7 +256,6 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
setInitialText("");
const pathParts = [String(dataKey ?? nanoid()), instanceIdRef.current];
if (schema) pathParts.push(String(schema));
pathParts.push(language);
setModelPath(pathParts.join("."));
@@ -297,7 +270,7 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
return () => {
cancelled = true;
};
}, [open, dataKey, language, schema]);
}, [open, dataKey, language]);
/* eslint-enable @eslint-react/hooks-extra/no-direct-set-state-in-use-effect */
const onMount = async (editor: monaco.editor.IStandaloneCodeEditor) => {
-2
View File
@@ -834,7 +834,6 @@ export const ProfileItem = (props: Props) => {
initialData={() => readProfileFile(uid)}
dataKey={uid}
language="yaml"
schema="clash"
onSave={async (prev, curr) => {
await saveProfileFile(uid, curr ?? "");
onSave?.(prev, curr);
@@ -881,7 +880,6 @@ export const ProfileItem = (props: Props) => {
initialData={() => readProfileFile(option?.merge ?? "")}
dataKey={`merge:${option?.merge ?? ""}`}
language="yaml"
schema="merge"
onSave={async (prev, curr) => {
await saveProfileFile(option?.merge ?? "", curr ?? "");
onSave?.(prev, curr);
-1
View File
@@ -184,7 +184,6 @@ export const ProfileMore = (props: Props) => {
initialData={() => readProfileFile(id)}
dataKey={id}
language={id === "Merge" ? "yaml" : "javascript"}
schema={id === "Merge" ? "merge" : undefined}
onSave={async (prev, curr) => {
await saveProfileFile(id, curr ?? "");
onSave?.(prev, curr);
@@ -35,7 +35,6 @@ export const ConfigViewer = forwardRef<DialogRef>((_, ref) => {
dataKey="runtime-config"
readOnly
language="yaml"
schema="clash"
onClose={() => setOpen(false)}
/>
);