File tree Expand file tree Collapse file tree 13 files changed +121
-46
lines changed
app/components/code-capture Expand file tree Collapse file tree 13 files changed +121
-46
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export default function CodeImagePreview() {
18
18
} }
19
19
>
20
20
< div
21
- className = "window flex flex-col bg-[#353742af] border rounded-md border-[#82738E]"
21
+ className = "window flex flex-col border rounded-md border-[#82738E]"
22
22
style = { {
23
23
width : windowWidth ,
24
24
} }
Original file line number Diff line number Diff line change @@ -9,12 +9,15 @@ import {
9
9
SelectValue ,
10
10
} from "@/components/ui/select" ;
11
11
import useStore from "@/lib/store/store" ;
12
- import { setTheme } from "@/lib/editor/themes/change-theme" ;
13
12
14
13
import themeList from "monaco-themes/themes/themelist.json" ;
15
14
import editorLanguages from "@/lib/editor/languages/editor-languages" ;
15
+ import useEditorTheme from "@/hooks/editor-theme" ;
16
16
17
17
export default function ControlOptions ( ) {
18
+ // hook
19
+ const { updateEditorWindowTheme } = useEditorTheme ( ) ;
20
+
18
21
// store
19
22
const changeEditorTheme = useStore ( ( state ) => state . changeEditorTheme ) ;
20
23
const changeEditorLanguage = useStore ( ( state ) => state . changeEditorLanguage ) ;
@@ -49,7 +52,7 @@ export default function ControlOptions() {
49
52
< Select
50
53
onValueChange = { ( value ) => {
51
54
changeEditorTheme ( value ) ;
52
- setTheme ( value ) ;
55
+ updateEditorWindowTheme ( ) ;
53
56
} }
54
57
>
55
58
< SelectTrigger >
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export default function WindowContent() {
14
14
` ;
15
15
16
16
return (
17
- < div className = "content rounded-b-md opacity-90 h-60" >
17
+ < div className = "content rounded-b-md h-60" >
18
18
< MonacoEditor />
19
19
</ div >
20
20
) ;
Original file line number Diff line number Diff line change
1
+ import { cn } from "@/lib/utils" ;
1
2
import WindowButtons from "./window-buttons" ;
3
+ import useStore from "@/lib/store/store" ;
2
4
3
5
export default function WindowHeader ( ) {
6
+ const editorThemeColors = useStore ( ( state ) => state . editorThemeColors ) ;
7
+
8
+ console . log ( "edit" , editorThemeColors ) ;
9
+
4
10
return (
5
- < div className = "window-header rounded-t-md flex justify-between w-full py-3 px-4 items-center" >
11
+ < div
12
+ className = "window-header rounded-t-md flex justify-between w-full py-3 px-4 items-center"
13
+ style = { {
14
+ background : editorThemeColors [ "editor.background" ] ,
15
+ } }
16
+ >
6
17
< WindowButtons />
7
18
8
19
< div className = "window-title" >
Original file line number Diff line number Diff line change
1
+ import { applyTheme } from "@/lib/editor/themes/apply-theme" ;
2
+ import useStore from "@/lib/store/store" ;
3
+
4
+ export default function useEditorTheme ( ) {
5
+
6
+ const editorTheme = useStore ( ( state ) => state . editorTheme ) ;
7
+ const editorThemeColors = useStore ( ( state ) => state . editorThemeColors ) ;
8
+ const changeEditorThemeColors = useStore (
9
+ ( state ) => state . changeEditorThemeColors
10
+ ) ;
11
+
12
+ const updateEditorWindowTheme = async ( ) => {
13
+ const colors = await applyTheme ( editorTheme ) ;
14
+ changeEditorThemeColors ( colors ) ;
15
+ 13 ;
16
+ } ;
17
+
18
+ return { updateEditorWindowTheme } ;
19
+ }
Original file line number Diff line number Diff line change 1
1
import { loader } from "@monaco-editor/react" ;
2
2
3
- const setTheme = async ( themeName : string ) => {
3
+ const applyTheme = async ( themeName : string ) => {
4
4
console . log ( themeName ) ;
5
5
let themeData = await import ( `monaco-themes/themes/${ themeName } .json` ) ;
6
- themeData = { ...themeData } ;
7
6
8
7
themeName &&
9
8
loader . init ( ) . then ( ( monaco ) => {
10
9
if ( themeName . split ( " " ) . length > 1 ) {
11
- console . log ( "yes" ) ;
12
10
themeName = themeName . split ( " " ) [ 0 ] + "-" + themeName . split ( " " ) [ 1 ] ;
13
11
}
14
- monaco . editor . defineTheme ( themeName , themeData ) ;
12
+ monaco . editor . defineTheme ( themeName , { ... themeData } ) ;
15
13
monaco . editor . setTheme ( themeName ) ;
16
14
} ) ;
17
15
18
- return { ... themeData } ;
16
+ return themeData . colors ;
19
17
} ;
20
18
21
- export { setTheme } ;
19
+ export { applyTheme } ;
Original file line number Diff line number Diff line change 3
3
import { Editor , MonacoDiffEditor } from "@monaco-editor/react" ;
4
4
import React from "react" ;
5
5
import useStore from "./store/store" ;
6
- import { setTheme } from "./editor/themes/change-theme" ;
7
- import { Languages } from "lucide-react" ;
6
+ import useEditorTheme from "@/hooks/editor-theme" ;
8
7
9
8
export default function MonacoEditor ( ) {
10
9
const editorRef = React . useRef < MonacoDiffEditor > ( null ) ;
11
10
11
+ const { updateEditorWindowTheme } = useEditorTheme ( ) ;
12
+
12
13
const windowWidth = useStore ( ( state ) => state . windowWidth ) ;
13
14
const changeWindowWidth = useStore ( ( state ) => state . changeWindowWidth ) ;
14
15
15
- const editorTheme = useStore ( ( state ) => state . editorTheme ) ;
16
16
const editorLanguage = useStore ( ( state ) => state . editorLanguage ) ;
17
17
18
18
// to adjust editor width based on its content
@@ -27,7 +27,7 @@ export default function MonacoEditor() {
27
27
}
28
28
} ;
29
29
30
- console . log ( ' changed language' , editorLanguage ) ;
30
+ console . log ( " changed language" , editorLanguage ) ;
31
31
32
32
return (
33
33
< Editor
@@ -41,11 +41,10 @@ export default function MonacoEditor() {
41
41
theme = "vs-dark"
42
42
onMount = { ( editor ) => {
43
43
editorRef . current = editor ;
44
- setTheme ( editorTheme ) ;
44
+ updateEditorWindowTheme ( ) ;
45
45
} }
46
- onChange = { ( editor , monaco ) => {
46
+ onChange = { ( ) => {
47
47
controlEditorWidth ( ) ;
48
- // detectModel()
49
48
} }
50
49
options = { {
51
50
lineNumbers : "off" ,
Original file line number Diff line number Diff line change
1
+ import EditorSlice from "@/lib/types/store/slices/editor-slice" ;
2
+ import { SetState } from "@/lib/types/store/store" ;
3
+
4
+ export default function createEditorSlice ( set : SetState ) : EditorSlice {
5
+ return {
6
+ editorTheme : "Night Owl" ,
7
+ changeEditorTheme : ( theme ) =>
8
+ set ( ( ) => ( {
9
+ editorTheme : theme ,
10
+ } ) ) ,
11
+
12
+ editorLanguage : "javascript" ,
13
+ changeEditorLanguage : ( language ) =>
14
+ set ( ( ) => ( {
15
+ editorLanguage : language ,
16
+ } ) ) ,
17
+
18
+ editorThemeColors : {
19
+ "editor.background" : "" ,
20
+ } ,
21
+ changeEditorThemeColors : ( themeColors ) =>
22
+ set ( ( ) => ( {
23
+ editorThemeColors : themeColors ,
24
+ } ) ) ,
25
+ } ;
26
+ }
Original file line number Diff line number Diff line change
1
+ import WindowSlice from "@/lib/types/store/slices/window-slice" ;
2
+ import { SetState } from "@/lib/types/store/store" ;
3
+
4
+ export default function createWindowSlice ( set : SetState ) : WindowSlice {
5
+ return {
6
+ windowWidth : 600 ,
7
+ changeWindowWidth : ( newWidth ) =>
8
+ set ( ( ) => ( {
9
+ windowWidth : newWidth ,
10
+ } ) ) ,
11
+ } ;
12
+ }
Original file line number Diff line number Diff line change 1
1
import { create } from "zustand" ;
2
-
3
- interface StoreStates {
4
- windowWidth : number ;
5
- changeWindowWidth : ( newWidth : number ) => void ;
6
-
7
- editorTheme : string ;
8
- changeEditorTheme : ( theme : string ) => void ;
9
-
10
- editorLanguage : string ;
11
- changeEditorLanguage : ( language : string ) => void ;
12
- }
2
+ import createWindowSlice from "./slices/window-slice" ;
3
+ import createEditorSlice from "./slices/editor-slice" ;
4
+ import { StoreStates } from "../types/store/store" ;
13
5
14
6
const useStore = create < StoreStates > ( ) ( ( set ) => ( {
15
- windowWidth : 600 ,
16
- changeWindowWidth : ( newWidth ) =>
17
- set ( ( ) => ( {
18
- windowWidth : newWidth ,
19
- } ) ) ,
20
-
21
- editorTheme : "Night Owl" ,
22
- changeEditorTheme : ( theme ) =>
23
- set ( ( ) => ( {
24
- editorTheme : theme ,
25
- } ) ) ,
26
-
27
- editorLanguage : "javascript" ,
28
- changeEditorLanguage : ( language ) =>
29
- set ( ( ) => ( {
30
- editorLanguage : language ,
31
- } ) ) ,
7
+ ...createWindowSlice ( set ) ,
8
+ ...createEditorSlice ( set ) ,
32
9
} ) ) ;
33
10
34
11
export default useStore ;
Original file line number Diff line number Diff line change
1
+ export interface EditorThemeColors {
2
+ "editor.background" : string ;
3
+ }
4
+
5
+ export default interface EditorSlice {
6
+ editorTheme : string ;
7
+ changeEditorTheme : ( theme : string ) => void ;
8
+
9
+ editorLanguage : string ;
10
+ changeEditorLanguage : ( language : string ) => void ;
11
+
12
+ editorThemeColors : EditorThemeColors ;
13
+ changeEditorThemeColors : ( themeColors : EditorThemeColors ) => void ;
14
+ }
Original file line number Diff line number Diff line change
1
+ export default interface WindowSlice {
2
+ windowWidth : number ;
3
+ changeWindowWidth : ( newWidth : number ) => void ;
4
+ }
Original file line number Diff line number Diff line change
1
+ import EditorSlice from "./slices/editor-slice" ;
2
+ import WindowSlice from "./slices/window-slice" ;
3
+
4
+ export type StoreStates = WindowSlice & EditorSlice ;
5
+
6
+ export type SetState = (
7
+ partial :
8
+ | StoreStates
9
+ | Partial < StoreStates >
10
+ | ( ( state : StoreStates ) => StoreStates | Partial < StoreStates > ) ,
11
+ replace ?: boolean | undefined
12
+ ) => void ;
You can’t perform that action at this time.
0 commit comments