refactor(imports): update SUPPORTED_LANGUAGES and SUPPORTED_THEMES import path to use editor folder feat(constants): add MIN_FONT_SIZE、MAX_FONT_SIZE and DEFAULT_FONT_SIZE feat(store): add font size management to code editor store
25 lines
804 B
TypeScript
25 lines
804 B
TypeScript
import { create } from "zustand";
|
|
import { CodeEditorState } from "@/types";
|
|
import { DEFAULT_THEME } from "@/constants/editor/themes";
|
|
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(
|
|
(set) => ({
|
|
language: DEFAULT_LANGUAGE,
|
|
theme: DEFAULT_THEME,
|
|
fontSize: DEFAULT_FONT_SIZE,
|
|
|
|
setLanguage: (language: string) => set({ language }),
|
|
setTheme: (theme: string) => set({ theme }),
|
|
setFontSize: (fontSize: number) => set({ fontSize }),
|
|
}),
|
|
{
|
|
name: "code-editor-storage",
|
|
storage: createJSONStorage(() => localStorage),
|
|
}
|
|
)
|
|
);
|