-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathOutput.vue
111 lines (101 loc) · 2.53 KB
/
Output.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script setup lang="ts">
import Preview from './Preview.vue'
import SplitPane from '../SplitPane.vue'
import { computed, inject, useTemplateRef } from 'vue'
import {
type ConsoleComponentType,
type EditorComponentType,
type OutputModes,
injectKeyProps,
} from '../types'
const props = defineProps<{
editorComponent: EditorComponentType
consoleComponent: ConsoleComponentType
showCompileOutput?: boolean
ssr: boolean
}>()
const { store, showConsole } = inject(injectKeyProps)!
const previewRef = useTemplateRef('preview')
const modes = computed(() =>
props.showCompileOutput
? (['preview', 'js', 'css', 'ssr'] as const)
: (['preview'] as const),
)
const mode = computed<OutputModes>({
get: () =>
(modes.value as readonly string[]).includes(store.value.outputMode)
? store.value.outputMode
: 'preview',
set(value) {
if ((modes.value as readonly string[]).includes(store.value.outputMode)) {
store.value.outputMode = value
}
},
})
function reload() {
previewRef.value?.reload()
store.value.clearConsole?.()
}
defineExpose({ reload, previewRef })
</script>
<template>
<div class="tab-buttons">
<button
v-for="m of modes"
:key="m"
:class="{ active: mode === m }"
@click="mode = m"
>
<span>{{ m }}</span>
</button>
</div>
<div class="output-container">
<SplitPane v-if="showConsole" layout="vertical">
<template #left>
<Preview ref="preview" :show="mode === 'preview'" :ssr="ssr" />
</template>
<template #right>
<props.consoleComponent />
</template>
</SplitPane>
<Preview v-else ref="preview" :show="mode === 'preview'" :ssr="ssr" />
<props.editorComponent
v-if="mode !== 'preview'"
readonly
:filename="store.activeFile.filename"
:value="store.activeFile.compiled[mode]"
:mode="mode"
/>
</div>
</template>
<style scoped>
.output-container {
height: calc(100% - var(--header-height));
overflow: hidden;
position: relative;
}
.tab-buttons {
box-sizing: border-box;
border-bottom: 1px solid var(--border);
background-color: var(--bg);
height: var(--header-height);
overflow: hidden;
}
.tab-buttons button {
padding: 0;
box-sizing: border-box;
}
.tab-buttons span {
font-size: 13px;
font-family: var(--font-code);
text-transform: uppercase;
color: var(--text-light);
display: inline-block;
padding: 8px 16px 6px;
line-height: 20px;
}
button.active {
color: var(--color-branding-dark);
border-bottom: 3px solid var(--color-branding-dark);
}
</style>