diff --git a/package.json b/package.json index 12a1a58..830db99 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "zustand": "^5.0.2" }, "devDependencies": { + "@shikijs/monaco": "^1.24.4", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", @@ -36,6 +37,7 @@ "eslint-config-next": "15.0.3", "postcss": "^8", "prisma": "^6.1.0", + "shiki": "^1.24.4", "tailwindcss": "^3.4.1", "typescript": "^5" } diff --git a/src/constants/themes.ts b/src/constants/themes.ts new file mode 100644 index 0000000..8e2b3fd --- /dev/null +++ b/src/constants/themes.ts @@ -0,0 +1,21 @@ +import { createHighlighter } from "shiki"; +import { Monaco } from "@monaco-editor/react"; +import { shikiToMonaco } from "@shikijs/monaco"; +import { SUPPORTED_LANGUAGES } from "./languages"; + +export const SUPPORTED_THEMES = ["vitesse-dark", "vitesse-light"]; + +export const DEFAULT_THEME = SUPPORTED_THEMES[0]; + +export const highlightMonacoEditor = async (monaco: Monaco) => { + const highlighter = await createHighlighter({ + themes: SUPPORTED_THEMES, + langs: SUPPORTED_LANGUAGES.map((lang) => lang.key), + }); + + for (const lang of SUPPORTED_LANGUAGES) { + monaco.languages.register({ id: lang.key }); + } + + shikiToMonaco(highlighter, monaco); +}; diff --git a/src/store/useCodeEditorStore.ts b/src/store/useCodeEditorStore.ts index e46c7ab..71ad224 100644 --- a/src/store/useCodeEditorStore.ts +++ b/src/store/useCodeEditorStore.ts @@ -1,5 +1,6 @@ import { create } from "zustand"; import { CodeEditorState } from "@/types"; +import { DEFAULT_THEME } from "@/constants/themes"; import { DEFAULT_LANGUAGE } from "@/constants/languages"; import { persist, createJSONStorage } from "zustand/middleware"; @@ -7,10 +8,12 @@ export const useCodeEditorStore = create()( persist( (set, get) => ({ language: DEFAULT_LANGUAGE, + theme: DEFAULT_THEME, setLanguage: (language: string) => set({ language }), + setTheme: (theme: string) => set({ theme }), }), { - name: "language-storage", + name: "code-editor-storage", storage: createJSONStorage(() => localStorage), } ) diff --git a/src/types/index.ts b/src/types/index.ts index f681da6..44ecddc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,5 +1,7 @@ export interface CodeEditorState { language: string; + theme: string; setLanguage: (language: string) => void; + setTheme: (theme: string) => void; }