1
1
<script setup lang="ts">
2
2
import Preview from ' ./Preview.vue'
3
3
import SplitPane from ' ../SplitPane.vue'
4
+ import { computed , inject , useTemplateRef } from ' vue'
4
5
import {
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 ,
15
7
type EditorComponentType ,
16
- type LogPayload ,
17
8
type OutputModes ,
18
9
injectKeyProps ,
19
10
} from ' ../types'
20
11
21
12
const props = defineProps <{
22
13
editorComponent: EditorComponentType
14
+ consoleComponent: ConsoleComponentType
23
15
showCompileOutput? : boolean
24
16
ssr: boolean
25
17
}>()
26
18
27
- const { store, showConsole, theme } = inject (injectKeyProps )!
19
+ const { store, showConsole } = inject (injectKeyProps )!
28
20
const 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
- }
65
21
66
22
const modes = computed (() =>
67
23
props .showCompileOutput
@@ -81,17 +37,9 @@ const mode = computed<OutputModes>({
81
37
},
82
38
})
83
39
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
-
92
40
function reload() {
93
41
previewRef .value ?.reload ()
94
- clearLunaConsole ()
42
+ // clearLunaConsole()
95
43
}
96
44
97
45
defineExpose ({ reload , previewRef })
@@ -112,16 +60,10 @@ defineExpose({ reload, previewRef })
112
60
<div class =" output-container" >
113
61
<SplitPane v-if =" showConsole" layout =" vertical" >
114
62
<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" />
121
64
</template >
122
65
<template #right >
123
- <div ref =" console-container" />
124
- <button class =" clear-btn" @click =" clearLunaConsole" >clear</button >
66
+ <props .consoleComponent />
125
67
</template >
126
68
</SplitPane >
127
69
<Preview v-else ref =" preview" :show =" mode === 'preview'" :ssr =" ssr" />
@@ -166,23 +108,4 @@ button.active {
166
108
color : var (--color-branding-dark );
167
109
border-bottom : 3px solid var (--color-branding-dark );
168
110
}
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
- }
188
111
</style >
0 commit comments