Skip to content

Commit

Permalink
fix: #212
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Dec 30, 2023
1 parent fee3885 commit 190a36a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:nightly": "tauri build -f default-meta nightly -c ./backend/tauri/tauri.nightly.conf.json",
"tauri": "tauri",
"web:dev": "vite",
"web:build": "tsc --noEmit && vite build",
"web:build": "vite build",
"web:serve": "vite preview",
"lint": "run-s lint:*",
"lint:prettier": "prettier --check .",
Expand Down
21 changes: 9 additions & 12 deletions src/components/profile/editor-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { useEffect, useRef } from "react";
import { useLockFn } from "ahooks";
import { useRecoilValue } from "recoil";
import { useTranslation } from "react-i18next";
import { readProfileFile, saveProfileFile } from "@/services/cmds";
import { atomThemeMode } from "@/services/states";
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
} from "@mui/material";
import { atomThemeMode } from "@/services/states";
import { readProfileFile, saveProfileFile } from "@/services/cmds";
import { useLockFn } from "ahooks";
import { useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { useRecoilValue } from "recoil";

import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js";
import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js";
import "monaco-editor/esm/vs/editor/contrib/folding/browser/folding.js";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
import { useNotification } from "@/hooks/use-notification";
import { monaco } from "@/services/monaco";

interface Props {
uid: string;
Expand All @@ -31,7 +28,7 @@ export const EditorViewer = (props: Props) => {

const { t } = useTranslation();
const editorRef = useRef<any>();
const instanceRef = useRef<editor.IStandaloneCodeEditor | null>(null);
const instanceRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
const themeMode = useRecoilValue(atomThemeMode);

useEffect(() => {
Expand All @@ -43,7 +40,7 @@ export const EditorViewer = (props: Props) => {
if (!dom) return;
if (instanceRef.current) instanceRef.current.dispose();

instanceRef.current = editor.create(editorRef.current, {
instanceRef.current = monaco.editor.create(editorRef.current, {
value: data,
language: mode,
theme: themeMode === "light" ? "vs" : "vs-dark",
Expand Down
9 changes: 3 additions & 6 deletions src/components/setting/mods/config-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BaseDialog, DialogRef } from "@/components/base";
import { getRuntimeYaml } from "@/services/cmds";
import { atomThemeMode } from "@/services/states";
import { Chip } from "@mui/material";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
import {
forwardRef,
useEffect,
Expand All @@ -13,16 +12,14 @@ import {
import { useTranslation } from "react-i18next";
import { useRecoilValue } from "recoil";

import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js";
import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js";
import "monaco-editor/esm/vs/editor/contrib/folding/browser/folding.js";
import { monaco } from "@/services/monaco";

export const ConfigViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation();
const [open, setOpen] = useState(false);

const editorRef = useRef<any>();
const instanceRef = useRef<editor.IStandaloneCodeEditor | null>(null);
const instanceRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
const themeMode = useRecoilValue(atomThemeMode);

useEffect(() => {
Expand All @@ -44,7 +41,7 @@ export const ConfigViewer = forwardRef<DialogRef>((props, ref) => {
if (!dom) return;
if (instanceRef.current) instanceRef.current.dispose();

instanceRef.current = editor.create(editorRef.current, {
instanceRef.current = monaco.editor.create(editorRef.current, {
value: data ?? "# Error\n",
language: "yaml",
theme: themeMode === "light" ? "vs" : "vs-dark",
Expand Down
10 changes: 10 additions & 0 deletions src/services/monaco.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// features
import "monaco-editor/esm/vs/editor/editor.all.js";

// langs
import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js";
import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js";

import * as monaco from "monaco-editor/esm/vs/editor/editor.api";

export { monaco };

0 comments on commit 190a36a

Please sign in to comment.