mirror of
https://litchi.icu/ngc2207/judge.git
synced 2025-05-18 20:36:43 +00:00
feat(editor): add editor state management to CodeEditorStore
This commit is contained in:
parent
bc39266f2c
commit
fe0c27da0a
@ -1,9 +1,10 @@
|
||||
import { create } from "zustand";
|
||||
import { editor } from "monaco-editor";
|
||||
import { CodeEditorState } from "@/types";
|
||||
import { DEFAULT_THEME } from "@/constants/editor/themes";
|
||||
import { DEFAULT_FONT_SIZE } from "@/constants/editor/options";
|
||||
import { DEFAULT_LANGUAGE } from "@/constants/editor/languages";
|
||||
import { persist, createJSONStorage } from "zustand/middleware";
|
||||
import { DEFAULT_FONT_SIZE } from "@/constants/editor/options";
|
||||
|
||||
export const useCodeEditorStore = create<CodeEditorState>()(
|
||||
persist(
|
||||
@ -11,14 +12,21 @@ export const useCodeEditorStore = create<CodeEditorState>()(
|
||||
language: DEFAULT_LANGUAGE,
|
||||
theme: DEFAULT_THEME,
|
||||
fontSize: DEFAULT_FONT_SIZE,
|
||||
editor: null,
|
||||
|
||||
setLanguage: (language: string) => set({ language }),
|
||||
setTheme: (theme: string) => set({ theme }),
|
||||
setFontSize: (fontSize: number) => set({ fontSize }),
|
||||
setEditor: (editor: editor.IStandaloneCodeEditor) => set({ editor }),
|
||||
}),
|
||||
{
|
||||
name: "code-editor-storage",
|
||||
storage: createJSONStorage(() => localStorage),
|
||||
partialize: (state) => ({
|
||||
language: state.language,
|
||||
theme: state.theme,
|
||||
fontSize: state.fontSize,
|
||||
}),
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -1,9 +1,13 @@
|
||||
import { editor } from "monaco-editor";
|
||||
|
||||
export interface CodeEditorState {
|
||||
language: string;
|
||||
theme: string;
|
||||
fontSize: number;
|
||||
editor: editor.IStandaloneCodeEditor | null;
|
||||
|
||||
setLanguage: (language: string) => void;
|
||||
setTheme: (theme: string) => void;
|
||||
setFontSize: (fontSize: number) => void;
|
||||
setEditor: (editor: editor.IStandaloneCodeEditor) => void;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user