diff --git a/package.json b/package.json index accdc06..390d4c0 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "dayjs": "1.11.5", "i18next": "^23.11.3", "lodash-es": "^4.17.21", - "meta-json-schema": "1.18.4-beta4", + "meta-json-schema": "1.18.4-beta5", "monaco-editor": "^0.47.0", "monaco-yaml": "^5.1.1", "nanoid": "^5.0.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 345484f..ba072af 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,8 +62,8 @@ importers: specifier: ^4.17.21 version: 4.17.21 meta-json-schema: - specifier: 1.18.4-beta4 - version: 1.18.4-beta4 + specifier: 1.18.4-beta5 + version: 1.18.4-beta5 monaco-editor: specifier: ^0.47.0 version: 0.47.0 @@ -2444,10 +2444,10 @@ packages: integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==, } - meta-json-schema@1.18.4-beta4: + meta-json-schema@1.18.4-beta5: resolution: { - integrity: sha512-CRyl8cv53LlzAKGdG5NyoUu7LwTL0NjDWqARuYEiQXPKBQPqEYh0MlZtQOTsFwfdTaaxUHZQZDAotRW7DudfxA==, + integrity: sha512-Z0+VeKEK6Oh2qAhwCg9kD9tHIoTs9ktqIuG2nV2PZ/vam6ZWCXYkN6yl0AF/75gKqSxfprDAaC8Xaun+8ta8CA==, } micromark-core-commonmark@2.0.1: @@ -4969,7 +4969,7 @@ snapshots: merge-stream@2.0.0: {} - meta-json-schema@1.18.4-beta4: {} + meta-json-schema@1.18.4-beta5: {} micromark-core-commonmark@2.0.1: dependencies: diff --git a/src/components/profile/editor-viewer.tsx b/src/components/profile/editor-viewer.tsx index 2236bf2..966af8a 100644 --- a/src/components/profile/editor-viewer.tsx +++ b/src/components/profile/editor-viewer.tsx @@ -23,12 +23,13 @@ import metaSchema from "meta-json-schema/schemas/meta-json-schema.json"; import mergeSchema from "meta-json-schema/schemas/clash-verge-merge-json-schema.json"; interface Props { - uid: string; + mode: "profile" | "text"; + property: string; open: boolean; - language: "yaml" | "javascript"; + language: "yaml" | "javascript" | "css"; schema?: "clash" | "merge"; onClose: () => void; - onChange?: () => void; + onChange?: (content?: string) => void; } // yaml worker @@ -50,7 +51,7 @@ configureMonacoYaml(monaco, { }); export const EditorViewer = (props: Props) => { - const { uid, open, language, schema, onClose, onChange } = props; + const { mode, property, open, language, schema, onClose, onChange } = props; const { t } = useTranslation(); const editorRef = useRef(); const instanceRef = useRef(null); @@ -59,7 +60,14 @@ export const EditorViewer = (props: Props) => { useEffect(() => { if (!open) return; - readProfileFile(uid).then((data) => { + let fetchContent; + switch (mode) { + case "profile": // profile文件 + fetchContent = readProfileFile(property); + case "text": // 文本内容 + fetchContent = Promise.resolve(property); + } + fetchContent.then((data) => { const dom = editorRef.current; if (!dom) return; @@ -71,7 +79,7 @@ export const EditorViewer = (props: Props) => { instanceRef.current = editor.create(editorRef.current, { model: model, language: language, - tabSize: ["yaml", "javascript"].includes(language) ? 2 : 4, // 根据语言类型设置缩进 + tabSize: ["yaml", "javascript", "css"].includes(language) ? 2 : 4, // 根据语言类型设置缩进 theme: themeMode === "light" ? "vs" : "vs-dark", minimap: { enabled: dom.clientWidth >= 1000 }, // 超过一定宽度显示minimap滚动条 mouseWheelZoom: true, // Ctrl+滚轮调节缩放 @@ -80,6 +88,9 @@ export const EditorViewer = (props: Props) => { comments: true, // 注释类型的建议 other: true, // 其他类型的建议 }, + padding: { + top: 33, // 顶部padding防止遮挡snippets + }, }); }); @@ -97,8 +108,10 @@ export const EditorViewer = (props: Props) => { if (value == null) return; try { - await saveProfileFile(uid, value); - onChange?.(); + if (mode === "profile") { + await saveProfileFile(property, value); + } + onChange?.(value); onClose(); } catch (err: any) { Notice.error(err.message || err.toString()); diff --git a/src/components/profile/profile-item.tsx b/src/components/profile/profile-item.tsx index 180a0ed..dc00843 100644 --- a/src/components/profile/profile-item.tsx +++ b/src/components/profile/profile-item.tsx @@ -20,7 +20,7 @@ import { RefreshRounded, DragIndicator } from "@mui/icons-material"; import { atomLoadingCache } from "@/services/states"; import { updateProfile, deleteProfile, viewProfile } from "@/services/cmds"; import { Notice } from "@/components/base"; -import { EditorViewer } from "./editor-viewer"; +import { EditorViewer } from "@/components/profile/editor-viewer"; import { ProfileBox } from "./profile-box"; import parseTraffic from "@/utils/parse-traffic"; import { ConfirmViewer } from "./confirm-viewer"; @@ -384,7 +384,8 @@ export const ProfileItem = (props: Props) => { { ((props, ref) => { const { t } = useTranslation(); const [open, setOpen] = useState(false); + const [editorOpen, setEditorOpen] = useState(false); const { verge, patchVerge } = useVerge(); const { theme_setting } = verge ?? {}; const [theme, setTheme] = useState(theme_setting || {}); @@ -108,14 +112,29 @@ export const ThemeViewer = forwardRef((props, ref) => { onKeyDown={(e) => e.key === "Enter" && onSave()} /> - - e.key === "Enter" && onSave()} + + { + theme.css_injection = content; + handleChange("css_injection"); + }} + onClose={() => { + setEditorOpen(false); + }} /> diff --git a/vite.config.ts b/vite.config.ts index 2891642..e533d4c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,7 +12,7 @@ export default defineConfig({ svgr(), react(), monacoEditor({ - languageWorkers: ["editorWorkerService", "typescript"], + languageWorkers: ["editorWorkerService", "typescript", "css"], customWorkers: [ { label: "yaml",