11<script setup lang="ts">
22import Preview from ' ./Preview.vue'
33import SplitPane from ' ../SplitPane.vue'
4+ import { computed , inject , useTemplateRef } from ' vue'
45import {
5- computed ,
6- inject ,
7- onMounted ,
8- ref ,
9- useTemplateRef ,
10- watch ,
11- type WatchHandle ,
12- } from ' vue'
13- import LunaConsole from ' luna-console'
14- import {
6+ type ConsoleComponentType ,
157 type EditorComponentType ,
16- type LogPayload ,
178 type OutputModes ,
189 injectKeyProps ,
1910} from ' ../types'
2011
2112const props = defineProps <{
2213 editorComponent: EditorComponentType
14+ consoleComponent: ConsoleComponentType
2315 showCompileOutput? : boolean
2416 ssr: boolean
2517}>()
2618
27- const { store, showConsole, theme } = inject (injectKeyProps )!
19+ const { store, showConsole } = inject (injectKeyProps )!
2820const previewRef = useTemplateRef (' preview' )
29- const consoleContainerRef = useTemplateRef (' console-container' )
30- const lunaConsole = ref <LunaConsole >()
31- let lunaWatcher: WatchHandle | undefined = undefined
32-
33- onMounted (createConsole )
34-
35- watch (
36- showConsole ,
37- (val ) => {
38- if (val ) {
39- createConsole ()
40- } else {
41- lunaConsole .value = undefined
42- lunaWatcher ?.stop ()
43- }
44- },
45- { flush: ' post' },
46- )
47-
48- function createConsole() {
49- if (! consoleContainerRef .value || lunaConsole .value ) return
50- lunaConsole .value = new LunaConsole (consoleContainerRef .value , {
51- theme: theme .value || ' light' ,
52- })
53- if (! lunaWatcher ) {
54- const consoleStyles = [
55- import (' luna-object-viewer/luna-object-viewer.css' ),
56- import (' luna-data-grid/luna-data-grid.css' ),
57- import (' luna-dom-viewer/luna-dom-viewer.css' ),
58- import (' luna-console/luna-console.css' ),
59- ]
60- Promise .all (consoleStyles )
61- lunaWatcher = watch (() => store .value .activeFile .code , clearLunaConsole )
62- }
63- lunaWatcher .resume ()
64- }
6521
6622const modes = computed (() =>
6723 props .showCompileOutput
@@ -81,17 +37,9 @@ const mode = computed<OutputModes>({
8137 },
8238})
8339
84- function onLog({ logLevel , data = [] }: LogPayload ) {
85- ;(lunaConsole .value ?.[logLevel ] as any )?.(... data )
86- }
87-
88- function clearLunaConsole() {
89- lunaConsole .value ?.clear (true )
90- }
91-
9240function reload() {
9341 previewRef .value ?.reload ()
94- clearLunaConsole ()
42+ // clearLunaConsole()
9543}
9644
9745defineExpose ({ reload , previewRef })
@@ -112,16 +60,10 @@ defineExpose({ reload, previewRef })
11260 <div class =" output-container" >
11361 <SplitPane v-if =" showConsole" layout =" vertical" >
11462 <template #left >
115- <Preview
116- ref =" preview"
117- :show =" mode === 'preview'"
118- :ssr =" ssr"
119- @log =" onLog"
120- />
63+ <Preview ref =" preview" :show =" mode === 'preview'" :ssr =" ssr" />
12164 </template >
12265 <template #right >
123- <div ref =" console-container" />
124- <button class =" clear-btn" @click =" clearLunaConsole" >clear</button >
66+ <props .consoleComponent />
12567 </template >
12668 </SplitPane >
12769 <Preview v-else ref =" preview" :show =" mode === 'preview'" :ssr =" ssr" />
@@ -166,23 +108,4 @@ button.active {
166108 color : var (--color-branding-dark );
167109 border-bottom : 3px solid var (--color-branding-dark );
168110}
169- .luna-console-theme-dark {
170- background-color : var (--bg ) !important ;
171- }
172- .clear-btn {
173- position : absolute ;
174- font-size : 18px ;
175- font-family : var (--font-code );
176- color : #999 ;
177- top : 10px ;
178- right : 10px ;
179- z-index : 99 ;
180- padding : 8px 10px 6px ;
181- background-color : var (--bg );
182- border-radius : 4px ;
183- border : 1px solid var (--border );
184- &:hover {
185- color : var (--color-branding );
186- }
187- }
188111 </style >
0 commit comments