@@ -17,55 +17,10 @@ import {
1717import Editor from '@monaco-editor/react' ;
1818import * as monaco from 'monaco-editor' ;
1919import type { Editor as TiptapEditor } from '@tiptap/react' ;
20+ import { useMonacoTheme } from '@/contexts/MonacoThemeContext' ;
2021
21- // CSS styles for theme overrides
22- const monacoThemeStyles = `
23- .monaco-light-override .monaco-editor,
24- .monaco-light-override .monaco-editor .margin,
25- .monaco-light-override .monaco-editor .monaco-editor-background {
26- background-color: #ffffff !important;
27- color: #000000 !important;
28- }
29-
30- .monaco-light-override .monaco-editor .view-lines .view-line {
31- color: #000000 !important;
32- }
33-
34- .monaco-light-override .monaco-editor .line-numbers {
35- color: #237893 !important;
36- }
37-
38- .monaco-light-override .monaco-editor .current-line {
39- background-color: #f0f0f0 !important;
40- }
41-
42- .monaco-light-override .monaco-editor .selected-text {
43- background-color: #316ac5 !important;
44- }
45-
46- .monaco-dark-override .monaco-editor,
47- .monaco-dark-override .monaco-editor .margin,
48- .monaco-dark-override .monaco-editor .monaco-editor-background {
49- background-color: #1e1e1e !important;
50- color: #d4d4d4 !important;
51- }
52-
53- .monaco-dark-override .monaco-editor .view-lines .view-line {
54- color: #d4d4d4 !important;
55- }
56-
57- .monaco-dark-override .monaco-editor .line-numbers {
58- color: #858585 !important;
59- }
60-
61- .monaco-dark-override .monaco-editor .current-line {
62- background-color: #2a2a2a !important;
63- }
64-
65- .monaco-dark-override .monaco-editor .selected-text {
66- background-color: #316ac5 !important;
67- }
68- ` ;
22+ // Monaco Editor has built-in themes: "vs" (light) and "vs-dark" (dark)
23+ // We'll use the theme prop to set each editor's theme individually
6924
7025interface ExecutableCodeBlockNodeViewProps {
7126 node : {
@@ -90,23 +45,6 @@ export function ExecutableCodeBlockNodeView({
9045 getPos,
9146 editor,
9247} : ExecutableCodeBlockNodeViewProps ) {
93- // Inject custom CSS styles for theme overrides
94- useEffect ( ( ) => {
95- const styleId = 'monaco-theme-override-styles' ;
96- let styleElement = document . getElementById ( styleId ) as HTMLStyleElement ;
97-
98- if ( ! styleElement ) {
99- styleElement = document . createElement ( 'style' ) ;
100- styleElement . id = styleId ;
101- styleElement . textContent = monacoThemeStyles ;
102- document . head . appendChild ( styleElement ) ;
103- }
104-
105- return ( ) => {
106- // Clean up when the last component unmounts
107- // Note: This is a simple approach. In production, you might want to reference count
108- } ;
109- } , [ ] ) ;
11048 const [ output , setOutput ] = useState < ExecutionResult | null > (
11149 node . attrs . output || null
11250 ) ;
@@ -119,9 +57,7 @@ export function ExecutableCodeBlockNodeView({
11957 const [ code , setCode ] = useState ( node . textContent ) ;
12058 const [ editorHeight , setEditorHeight ] = useState ( 300 ) ;
12159 const [ isResizing , setIsResizing ] = useState ( false ) ;
122- const [ monacoThemeOverride , setMonacoThemeOverride ] = useState <
123- 'light' | 'dark'
124- > ( 'dark' ) ;
60+ const { theme : monacoTheme , toggleTheme } = useMonacoTheme ( ) ;
12561 const nodeRef = useRef < HTMLDivElement > ( null ) ;
12662 const updateTimeoutRef = useRef < NodeJS . Timeout | undefined > ( undefined ) ;
12763 const monacoRef = useRef < monaco . editor . IStandaloneCodeEditor | null > ( null ) ;
@@ -339,15 +275,11 @@ export function ExecutableCodeBlockNodeView({
339275
340276 < div className = "flex items-center gap-1" >
341277 < button
342- onClick = { ( ) => {
343- setMonacoThemeOverride (
344- monacoThemeOverride === 'light' ? 'dark' : 'light'
345- ) ;
346- } }
278+ onClick = { toggleTheme }
347279 className = "rounded p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
348- title = { `Monaco theme: ${ monacoThemeOverride } (click to toggle)` }
280+ title = { `Monaco theme: ${ monacoTheme } (click to toggle all code blocks )` }
349281 >
350- { monacoThemeOverride === 'light' ? (
282+ { monacoTheme === 'light' ? (
351283 < Sun className = "h-4 w-4" />
352284 ) : (
353285 < Moon className = "h-4 w-4" />
@@ -398,17 +330,15 @@ export function ExecutableCodeBlockNodeView({
398330 </ div >
399331
400332 { /* Code Content */ }
401- < div
402- className = { `relative w-full ${ monacoThemeOverride === 'light' ? 'monaco-light-override' : 'monaco-dark-override' } ` }
403- >
333+ < div className = "relative w-full" >
404334 < Editor
405335 key = { `monaco-${ node . attrs . language } -${ getPos ( ) } ` }
406336 height = { `${ editorHeight } px` }
407337 width = "100%"
408338 language = { language }
409339 defaultValue = { code }
410340 onChange = { handleCodeChange }
411- theme = "vs -dark"
341+ theme = { monacoTheme === 'light' ? 'vs' : 'vs -dark' }
412342 options = { {
413343 minimap : { enabled : false } ,
414344 lineNumbers : 'on' ,
@@ -424,6 +354,7 @@ export function ExecutableCodeBlockNodeView({
424354 scrollbar : {
425355 verticalScrollbarSize : 10 ,
426356 horizontalScrollbarSize : 10 ,
357+ alwaysConsumeMouseWheel : false , // Allow scroll to pass through to parent
427358 } ,
428359 contextmenu : true ,
429360 renderLineHighlight : 'gutter' ,
0 commit comments