reiji-h 2 лет назад
Родитель
Сommit
4030538edc

+ 3 - 3
packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx

@@ -9,7 +9,7 @@ import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
 
 import { GlobalCodeMirrorEditorKey, AcceptedUploadFileType } from '../../consts';
 import {
-  useFileDropzone, FileDropzoneOverlay, getEditorTheme,
+  useFileDropzone, FileDropzoneOverlay, getEditorTheme, type EditorTheme,
 } from '../../services';
 import {
   getStrFromBol, adjustPasteData,
@@ -144,10 +144,10 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
 
   const [themeExtension, setThemeExtension] = useState<Extension | undefined>(undefined);
   useEffect(() => {
-    const settingTheme = async(name?: string) => {
+    const settingTheme = async(name?: EditorTheme) => {
       setThemeExtension(await getEditorTheme(name ?? 'DefaultLight'));
     };
-    settingTheme(editorTheme);
+    settingTheme(editorTheme as EditorTheme);
   }, [codeMirrorEditor, editorTheme, setThemeExtension]);
 
   useEffect(() => {

+ 1 - 3
packages/editor/src/components/playground/PlaygroundController.tsx

@@ -3,9 +3,7 @@ import { useCallback } from 'react';
 import { useForm } from 'react-hook-form';
 
 import { GlobalCodeMirrorEditorKey } from '../../consts';
-import {
-  AllEditorTheme,
-} from '../../services';
+import { AllEditorTheme } from '../../services';
 import { useCodeMirrorEditorIsolated } from '../../stores';
 
 export const InitEditorValueRow = (): JSX.Element => {

+ 17 - 2
packages/editor/src/services/editor-theme/index.ts

@@ -1,6 +1,6 @@
 import { Extension } from '@codemirror/state';
 
-export const getEditorTheme = async(themeName: string): Promise<Extension> => {
+export const getEditorTheme = async(themeName: EditorTheme): Promise<Extension> => {
   switch (themeName) {
     case 'Eclipse':
       return (await import('@uiw/codemirror-theme-eclipse')).eclipse;
@@ -24,4 +24,19 @@ export const getEditorTheme = async(themeName: string): Promise<Extension> => {
   return (await import('./original-light')).originalLight;
 };
 
-export const AllEditorTheme = ['DefaultLight', 'Eclipse', 'Basic', 'Ayu', 'Rosé Pine', 'DefaultDark', 'Material', 'Nord', 'Cobalt', 'Kimbie'];
+const EditorTheme = {
+  DefaultLight: 'DefaultLight',
+  Eclipse: 'Eclipse',
+  Basic: 'Basic',
+  Ayu: 'Ayu',
+  'Rosé Pine': 'Rosé Pine',
+  DefaultDark: 'DefaultDark',
+  Material: 'Material',
+  Nord: 'Nord',
+  Cobalt: 'Cobalt',
+  Kimbie: 'Kimbie',
+} as const;
+
+
+export const AllEditorTheme = Object.values(EditorTheme);
+export type EditorTheme = typeof EditorTheme[keyof typeof EditorTheme]