@@ -9,17 +9,9 @@ import {
9
9
JsonData ,
10
10
OnErrorFunction ,
11
11
defaultTheme ,
12
- // Additional Themes
13
- githubDarkTheme ,
14
- githubLightTheme ,
15
- monoLightTheme ,
16
- monoDarkTheme ,
17
- candyWrapperTheme ,
18
- psychedelicTheme ,
19
12
// ExternalTriggers,
20
13
// type CollapseState
21
14
} from './imports'
22
- import SourceIndicator from './SourceIndicator'
23
15
import { FaNpm , FaExternalLinkAlt , FaGithub } from 'react-icons/fa'
24
16
import { BiReset } from 'react-icons/bi'
25
17
import { AiOutlineCloudUpload } from 'react-icons/ai'
@@ -55,10 +47,10 @@ import { ArrowBackIcon, ArrowForwardIcon, InfoIcon } from '@chakra-ui/icons'
55
47
import { demoDataDefinitions } from './demoData'
56
48
import { useDatabase } from './useDatabase'
57
49
import './style.css'
58
- import { timestamp , version } from './version'
59
50
import { getLineHeight , truncate } from './helpers'
60
51
61
52
const CodeEditor = lazy ( ( ) => import ( './CodeEditor' ) )
53
+ const SourceIndicator = lazy ( ( ) => import ( './SourceIndicator' ) )
62
54
63
55
interface AppState {
64
56
rootName : string
@@ -79,18 +71,23 @@ interface AppState {
79
71
customTextEditor : boolean
80
72
}
81
73
82
- const themes = [
83
- defaultTheme ,
84
- githubDarkTheme ,
85
- githubLightTheme ,
86
- monoLightTheme ,
87
- monoDarkTheme ,
88
- candyWrapperTheme ,
89
- psychedelicTheme ,
74
+ // Additional themes are loaded dynamically when needed
75
+
76
+ const themeNames = [
77
+ 'Default' ,
78
+ 'Github Dark' ,
79
+ 'Github Light' ,
80
+ 'White & Black' ,
81
+ 'Black & White' ,
82
+ 'Candy Wrapper' ,
83
+ 'Psychedelic' ,
90
84
]
91
85
92
- console . log ( `json-edit-react v${ version } ` )
93
- console . log ( 'Site built:' , timestamp )
86
+ // Only default theme is loaded initially
87
+ const themes = [ defaultTheme ]
88
+
89
+ console . log ( `json-edit-react v${ __VERSION__ } ` )
90
+ console . log ( `Site built: ${ __BUILD_TIME__ } ` )
94
91
95
92
function App ( ) {
96
93
const navigate = useLocation ( ) [ 1 ]
@@ -231,9 +228,39 @@ function App() {
231
228
else navigate ( `./?data=${ selected } ` )
232
229
}
233
230
234
- const handleThemeChange = ( e : React . ChangeEvent < HTMLSelectElement > ) => {
235
- const theme = themes . find ( ( th ) => th . displayName === e . target . value )
231
+ const handleThemeChange = async ( e : React . ChangeEvent < HTMLSelectElement > ) => {
232
+ const themeName = e . target . value
233
+
234
+ // If theme is already loaded, use it
235
+ let theme = themes . find ( ( th ) => th . displayName === themeName )
236
+
237
+ // If theme is not loaded yet, load it using LazyThemes
238
+ if ( ! theme && themeName !== 'Default' ) {
239
+ try {
240
+ // Create a function name for the getter based on theme name
241
+ const functionName = `get${ themeName . replace ( / \s + & \s + | \s + / g, '' ) } Theme`
242
+
243
+ // Dynamically import the themes module
244
+ const lazyThemesModule = await import ( './theme/LazyThemes' )
245
+
246
+ // Get the theme using the themeGetters map
247
+ if ( lazyThemesModule . themeGetters [ functionName ] ) {
248
+ const newTheme = lazyThemesModule . themeGetters [ functionName ] ( )
249
+
250
+ // Add to available themes to avoid loading again
251
+ if ( newTheme ) {
252
+ themes . push ( newTheme )
253
+ theme = newTheme
254
+ }
255
+ }
256
+ } catch ( error ) {
257
+ console . error ( 'Failed to load theme:' , error )
258
+ return
259
+ }
260
+ }
261
+
236
262
if ( ! theme ) return
263
+
237
264
updateState ( { theme } )
238
265
if ( selectedDataSet === 'editTheme' ) {
239
266
setData ( theme )
@@ -291,7 +318,10 @@ function App() {
291
318
minH = "100%"
292
319
>
293
320
< HStack w = "100%" justify = "space-between" align = "flex-start" >
294
- < SourceIndicator />
321
+ < Suspense fallback = { null } >
322
+ < SourceIndicator />
323
+ </ Suspense >
324
+
295
325
< VStack align = "flex-start" gap = { 3 } >
296
326
< HStack align = "flex-end" mt = { 2 } gap = { 4 } flexWrap = "wrap" >
297
327
< Flex gap = { 4 } align = "center" >
@@ -626,9 +656,9 @@ function App() {
626
656
</ FormLabel >
627
657
< div className = "inputWidth" style = { { flexGrow : 1 } } >
628
658
< Select id = "themeSelect" onChange = { handleThemeChange } value = { theme . displayName } >
629
- { themes . map ( ( theme ) => (
630
- < option value = { theme . displayName } key = { theme . displayName } >
631
- { theme . displayName }
659
+ { themeNames . map ( ( themeName ) => (
660
+ < option value = { themeName } key = { themeName } >
661
+ { themeName }
632
662
</ option >
633
663
) ) }
634
664
</ Select >
@@ -826,7 +856,7 @@ function App() {
826
856
</ Flex >
827
857
< Box h = { 50 } />
828
858
< footer >
829
- < Text fontSize = "sm" > { `json-edit-react v${ version } ` } </ Text >
859
+ < Text fontSize = "sm" > { `json-edit-react v${ __VERSION__ } ` } </ Text >
830
860
</ footer >
831
861
</ div >
832
862
)
0 commit comments