mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 07:03:45 +08:00
feat: css injection editor
This commit is contained in:
parent
dc1abf8dcb
commit
da4bf167ee
@ -36,7 +36,7 @@
|
|||||||
"dayjs": "1.11.5",
|
"dayjs": "1.11.5",
|
||||||
"i18next": "^23.11.3",
|
"i18next": "^23.11.3",
|
||||||
"lodash-es": "^4.17.21",
|
"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-editor": "^0.47.0",
|
||||||
"monaco-yaml": "^5.1.1",
|
"monaco-yaml": "^5.1.1",
|
||||||
"nanoid": "^5.0.7",
|
"nanoid": "^5.0.7",
|
||||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@ -62,8 +62,8 @@ importers:
|
|||||||
specifier: ^4.17.21
|
specifier: ^4.17.21
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
meta-json-schema:
|
meta-json-schema:
|
||||||
specifier: 1.18.4-beta4
|
specifier: 1.18.4-beta5
|
||||||
version: 1.18.4-beta4
|
version: 1.18.4-beta5
|
||||||
monaco-editor:
|
monaco-editor:
|
||||||
specifier: ^0.47.0
|
specifier: ^0.47.0
|
||||||
version: 0.47.0
|
version: 0.47.0
|
||||||
@ -2444,10 +2444,10 @@ packages:
|
|||||||
integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==,
|
integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==,
|
||||||
}
|
}
|
||||||
|
|
||||||
meta-json-schema@1.18.4-beta4:
|
meta-json-schema@1.18.4-beta5:
|
||||||
resolution:
|
resolution:
|
||||||
{
|
{
|
||||||
integrity: sha512-CRyl8cv53LlzAKGdG5NyoUu7LwTL0NjDWqARuYEiQXPKBQPqEYh0MlZtQOTsFwfdTaaxUHZQZDAotRW7DudfxA==,
|
integrity: sha512-Z0+VeKEK6Oh2qAhwCg9kD9tHIoTs9ktqIuG2nV2PZ/vam6ZWCXYkN6yl0AF/75gKqSxfprDAaC8Xaun+8ta8CA==,
|
||||||
}
|
}
|
||||||
|
|
||||||
micromark-core-commonmark@2.0.1:
|
micromark-core-commonmark@2.0.1:
|
||||||
@ -4969,7 +4969,7 @@ snapshots:
|
|||||||
|
|
||||||
merge-stream@2.0.0: {}
|
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:
|
micromark-core-commonmark@2.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -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";
|
import mergeSchema from "meta-json-schema/schemas/clash-verge-merge-json-schema.json";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
uid: string;
|
mode: "profile" | "text";
|
||||||
|
property: string;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
language: "yaml" | "javascript";
|
language: "yaml" | "javascript" | "css";
|
||||||
schema?: "clash" | "merge";
|
schema?: "clash" | "merge";
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onChange?: () => void;
|
onChange?: (content?: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// yaml worker
|
// yaml worker
|
||||||
@ -50,7 +51,7 @@ configureMonacoYaml(monaco, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const EditorViewer = (props: Props) => {
|
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 { t } = useTranslation();
|
||||||
const editorRef = useRef<any>();
|
const editorRef = useRef<any>();
|
||||||
const instanceRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
const instanceRef = useRef<editor.IStandaloneCodeEditor | null>(null);
|
||||||
@ -59,7 +60,14 @@ export const EditorViewer = (props: Props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
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;
|
const dom = editorRef.current;
|
||||||
|
|
||||||
if (!dom) return;
|
if (!dom) return;
|
||||||
@ -71,7 +79,7 @@ export const EditorViewer = (props: Props) => {
|
|||||||
instanceRef.current = editor.create(editorRef.current, {
|
instanceRef.current = editor.create(editorRef.current, {
|
||||||
model: model,
|
model: model,
|
||||||
language: language,
|
language: language,
|
||||||
tabSize: ["yaml", "javascript"].includes(language) ? 2 : 4, // 根据语言类型设置缩进
|
tabSize: ["yaml", "javascript", "css"].includes(language) ? 2 : 4, // 根据语言类型设置缩进
|
||||||
theme: themeMode === "light" ? "vs" : "vs-dark",
|
theme: themeMode === "light" ? "vs" : "vs-dark",
|
||||||
minimap: { enabled: dom.clientWidth >= 1000 }, // 超过一定宽度显示minimap滚动条
|
minimap: { enabled: dom.clientWidth >= 1000 }, // 超过一定宽度显示minimap滚动条
|
||||||
mouseWheelZoom: true, // Ctrl+滚轮调节缩放
|
mouseWheelZoom: true, // Ctrl+滚轮调节缩放
|
||||||
@ -80,6 +88,9 @@ export const EditorViewer = (props: Props) => {
|
|||||||
comments: true, // 注释类型的建议
|
comments: true, // 注释类型的建议
|
||||||
other: true, // 其他类型的建议
|
other: true, // 其他类型的建议
|
||||||
},
|
},
|
||||||
|
padding: {
|
||||||
|
top: 33, // 顶部padding防止遮挡snippets
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -97,8 +108,10 @@ export const EditorViewer = (props: Props) => {
|
|||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await saveProfileFile(uid, value);
|
if (mode === "profile") {
|
||||||
onChange?.();
|
await saveProfileFile(property, value);
|
||||||
|
}
|
||||||
|
onChange?.(value);
|
||||||
onClose();
|
onClose();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Notice.error(err.message || err.toString());
|
Notice.error(err.message || err.toString());
|
||||||
|
@ -20,7 +20,7 @@ import { RefreshRounded, DragIndicator } from "@mui/icons-material";
|
|||||||
import { atomLoadingCache } from "@/services/states";
|
import { atomLoadingCache } from "@/services/states";
|
||||||
import { updateProfile, deleteProfile, viewProfile } from "@/services/cmds";
|
import { updateProfile, deleteProfile, viewProfile } from "@/services/cmds";
|
||||||
import { Notice } from "@/components/base";
|
import { Notice } from "@/components/base";
|
||||||
import { EditorViewer } from "./editor-viewer";
|
import { EditorViewer } from "@/components/profile/editor-viewer";
|
||||||
import { ProfileBox } from "./profile-box";
|
import { ProfileBox } from "./profile-box";
|
||||||
import parseTraffic from "@/utils/parse-traffic";
|
import parseTraffic from "@/utils/parse-traffic";
|
||||||
import { ConfirmViewer } from "./confirm-viewer";
|
import { ConfirmViewer } from "./confirm-viewer";
|
||||||
@ -384,7 +384,8 @@ export const ProfileItem = (props: Props) => {
|
|||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
<EditorViewer
|
<EditorViewer
|
||||||
uid={uid}
|
mode="profile"
|
||||||
|
property={uid}
|
||||||
open={fileOpen}
|
open={fileOpen}
|
||||||
language="yaml"
|
language="yaml"
|
||||||
schema="clash"
|
schema="clash"
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
import { FeaturedPlayListRounded } from "@mui/icons-material";
|
import { FeaturedPlayListRounded } from "@mui/icons-material";
|
||||||
import { viewProfile } from "@/services/cmds";
|
import { viewProfile } from "@/services/cmds";
|
||||||
import { Notice } from "@/components/base";
|
import { Notice } from "@/components/base";
|
||||||
import { EditorViewer } from "./editor-viewer";
|
import { EditorViewer } from "@/components/profile/editor-viewer";
|
||||||
import { ProfileBox } from "./profile-box";
|
import { ProfileBox } from "./profile-box";
|
||||||
import { LogViewer } from "./log-viewer";
|
import { LogViewer } from "./log-viewer";
|
||||||
import { ConfirmViewer } from "./confirm-viewer";
|
import { ConfirmViewer } from "./confirm-viewer";
|
||||||
@ -233,7 +233,8 @@ export const ProfileMore = (props: Props) => {
|
|||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
<EditorViewer
|
<EditorViewer
|
||||||
uid={uid}
|
mode="profile"
|
||||||
|
property={uid}
|
||||||
open={fileOpen}
|
open={fileOpen}
|
||||||
language={type === "merge" ? "yaml" : "javascript"}
|
language={type === "merge" ? "yaml" : "javascript"}
|
||||||
schema={type === "merge" ? "merge" : undefined}
|
schema={type === "merge" ? "merge" : undefined}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { forwardRef, useImperativeHandle, useState } from "react";
|
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
|
Button,
|
||||||
List,
|
List,
|
||||||
ListItem,
|
ListItem,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
@ -12,11 +13,14 @@ import {
|
|||||||
import { useVerge } from "@/hooks/use-verge";
|
import { useVerge } from "@/hooks/use-verge";
|
||||||
import { defaultTheme, defaultDarkTheme } from "@/pages/_theme";
|
import { defaultTheme, defaultDarkTheme } from "@/pages/_theme";
|
||||||
import { BaseDialog, DialogRef, Notice } from "@/components/base";
|
import { BaseDialog, DialogRef, Notice } from "@/components/base";
|
||||||
|
import { EditorViewer } from "@/components/profile/editor-viewer";
|
||||||
|
import { Edit, SwitchAccessShortcut } from "@mui/icons-material";
|
||||||
|
|
||||||
export const ThemeViewer = forwardRef<DialogRef>((props, ref) => {
|
export const ThemeViewer = forwardRef<DialogRef>((props, ref) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [editorOpen, setEditorOpen] = useState(false);
|
||||||
const { verge, patchVerge } = useVerge();
|
const { verge, patchVerge } = useVerge();
|
||||||
const { theme_setting } = verge ?? {};
|
const { theme_setting } = verge ?? {};
|
||||||
const [theme, setTheme] = useState(theme_setting || {});
|
const [theme, setTheme] = useState(theme_setting || {});
|
||||||
@ -108,14 +112,29 @@ export const ThemeViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
onKeyDown={(e) => e.key === "Enter" && onSave()}
|
onKeyDown={(e) => e.key === "Enter" && onSave()}
|
||||||
/>
|
/>
|
||||||
</Item>
|
</Item>
|
||||||
|
|
||||||
<Item>
|
<Item>
|
||||||
<ListItemText primary="CSS Injection" />
|
<ListItemText primary="CSS Injection" />
|
||||||
<TextField
|
<Button
|
||||||
{...textProps}
|
startIcon={<Edit />}
|
||||||
value={theme.css_injection ?? ""}
|
variant="outlined"
|
||||||
onChange={handleChange("css_injection")}
|
onClick={() => {
|
||||||
onKeyDown={(e) => e.key === "Enter" && onSave()}
|
setEditorOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("Edit")} CSS
|
||||||
|
</Button>
|
||||||
|
<EditorViewer
|
||||||
|
mode="text"
|
||||||
|
property={theme.css_injection ?? ""}
|
||||||
|
open={editorOpen}
|
||||||
|
language="css"
|
||||||
|
onChange={(content) => {
|
||||||
|
theme.css_injection = content;
|
||||||
|
handleChange("css_injection");
|
||||||
|
}}
|
||||||
|
onClose={() => {
|
||||||
|
setEditorOpen(false);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Item>
|
</Item>
|
||||||
</List>
|
</List>
|
||||||
|
@ -12,7 +12,7 @@ export default defineConfig({
|
|||||||
svgr(),
|
svgr(),
|
||||||
react(),
|
react(),
|
||||||
monacoEditor({
|
monacoEditor({
|
||||||
languageWorkers: ["editorWorkerService", "typescript"],
|
languageWorkers: ["editorWorkerService", "typescript", "css"],
|
||||||
customWorkers: [
|
customWorkers: [
|
||||||
{
|
{
|
||||||
label: "yaml",
|
label: "yaml",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user