11import { useEffect , useState , useContext , useRef , useCallback } from "react" ;
22import type { CSSProperties } from "react" ;
33import { useNavigate } from "react-router-dom" ;
4- import { ThemeProvider , createTheme , useMediaQuery , Container , Skeleton } from "@mui/material" ;
4+ import { ThemeProvider , createTheme , CssBaseline , useMediaQuery , Container , Skeleton } from "@mui/material" ;
55import { useWindowWidth } from "@react-hook/window-size" ;
66import type { BlockInterface , ElementInterface , PageInterface , SectionInterface , GlobalStyleInterface } from "../../helpers/Interfaces" ;
77import { ApiHelper , ArrayHelper , UserHelper } from "../../helpers" ;
@@ -24,6 +24,15 @@ import { ZoneBox } from "./ZoneBox";
2424import { EmptyState } from "./EmptyState" ;
2525import { useUndoRedo } from "../hooks/useUndoRedo" ;
2626import { HistoryPanel } from "./HistoryPanel" ;
27+ import { useThemeMode } from "../../ThemeContext" ;
28+
29+ const lightEditorTheme = createTheme ( {
30+ palette : { mode : "light" , background : { default : "#e5e8ee" , paper : "#ffffff" } } ,
31+ components : {
32+ MuiTextField : { defaultProps : { margin : "normal" } } ,
33+ MuiFormControl : { defaultProps : { margin : "normal" } }
34+ }
35+ } ) ;
2736
2837interface ConfigInterface {
2938 globalStyles ?: GlobalStyleInterface ;
@@ -81,6 +90,20 @@ export function ContentEditor(props: Props) {
8190 }
8291 } ;
8392
93+ // Force light mode while editor is mounted so preview matches the public website
94+ const { mode } = useThemeMode ( ) ;
95+ useEffect ( ( ) => {
96+ const wasInDarkMode = document . body . classList . contains ( "dark-theme" ) ;
97+ if ( wasInDarkMode ) {
98+ document . body . classList . remove ( "dark-theme" ) ;
99+ }
100+ return ( ) => {
101+ if ( wasInDarkMode ) {
102+ document . body . classList . add ( "dark-theme" ) ;
103+ }
104+ } ;
105+ } , [ ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
106+
84107 const [ showAdd , setShowAdd ] = useState ( false ) ;
85108 const [ showHelp , setShowHelp ] = useState ( false ) ;
86109 const css = StyleHelper . getCss ( container ?. sections || [ ] ) ;
@@ -374,22 +397,20 @@ export function ContentEditor(props: Props) {
374397 } ;
375398
376399 const getTheme = ( ) => {
400+ const base = {
401+ palette : { mode : "light" as const } ,
402+ components : {
403+ MuiTextField : { defaultProps : { margin : "normal" } } ,
404+ MuiFormControl : { defaultProps : { margin : "normal" } }
405+ }
406+ } ;
377407 if ( deviceType === "mobile" ) {
378408 return createTheme ( {
379- breakpoints : { values : { xs : 0 , sm : 2000 , md : 3000 , lg : 4000 , xl : 5000 } } ,
380- components : {
381- MuiTextField : { defaultProps : { margin : "normal" } } ,
382- MuiFormControl : { defaultProps : { margin : "normal" } }
383- }
384- } ) ;
385- } else {
386- return createTheme ( {
387- components : {
388- MuiTextField : { defaultProps : { margin : "normal" } } ,
389- MuiFormControl : { defaultProps : { margin : "normal" } }
390- }
409+ ...base ,
410+ breakpoints : { values : { xs : 0 , sm : 2000 , md : 3000 , lg : 4000 , xl : 5000 } }
391411 } ) ;
392412 }
413+ return createTheme ( base ) ;
393414 } ;
394415
395416 const getZoneBox = ( sections : SectionInterface [ ] , name : string , keyName : string ) => (
@@ -420,7 +441,8 @@ export function ContentEditor(props: Props) {
420441
421442 if ( ! container ) {
422443 return (
423- < >
444+ < ThemeProvider theme = { lightEditorTheme } >
445+ < CssBaseline />
424446 < Theme globalStyles = { props . config ?. globalStyles } appearance = { props . config ?. appearance } />
425447 < EditorToolbar
426448 onDone = { handleDone }
@@ -450,12 +472,14 @@ export function ContentEditor(props: Props) {
450472 < Skeleton variant = "rectangular" height = { 200 } sx = { { mb : 2 , borderRadius : 2 } } animation = "wave" />
451473 < Skeleton variant = "rectangular" height = { 200 } sx = { { mb : 2 , borderRadius : 2 } } animation = "wave" />
452474 </ Container >
453- </ >
475+ </ ThemeProvider >
454476 ) ;
455477 }
456478
457479 return (
458- < div style = { { display : "flex" , flexDirection : "column" , height : "calc(100vh - 64px)" , overflow : "hidden" } } >
480+ < ThemeProvider theme = { lightEditorTheme } >
481+ < CssBaseline />
482+ < div style = { { display : "flex" , flexDirection : "column" , height : "calc(100vh - 64px)" , overflow : "hidden" , backgroundColor : "#e5e8ee" } } >
459483 < Theme globalStyles = { props . config ?. globalStyles } appearance = { props . config ?. appearance } />
460484 < style > { css } </ style >
461485
@@ -568,5 +592,6 @@ export function ContentEditor(props: Props) {
568592 </ DndProvider >
569593 </ div >
570594 </ div >
595+ </ ThemeProvider >
571596 ) ;
572597}
0 commit comments