1
1
<script setup lang="ts">
2
- import { onMounted , ref } from ' vue'
3
- import Prism from ' vue-prism-component'
4
- import PrismJS from ' prismjs' ;
5
- const { highlight, languages } = PrismJS
6
-
7
2
import { Elysia } from ' elysia'
3
+ import { onMounted , ref , watch } from ' vue'
4
+ import { getHighlighterCore } from ' shiki/core'
5
+ import getWasm from ' shiki/wasm'
6
+ import javascript from ' shiki/langs/javascript.mjs'
7
+ import githubDark from ' shiki/themes/github-dark.mjs'
8
+ import githubLight from ' shiki/themes/github-light.mjs'
9
+ import useDark from ' ./use-dark'
10
+
11
+ const isDark = useDark ()
12
+
13
+ const highlighter = await getHighlighterCore ({
14
+ themes: [githubDark , githubLight ],
15
+ langs: [javascript ],
16
+ loadWasm: getWasm
17
+ })
18
+
8
19
9
- let code = ` const app = new Elysia()
10
- .get('/', () => 'Hello!' )
20
+ let code = /* js */ ` const app = new Elysia()
21
+ .get('/', () => ({ some: "json" }) )
11
22
// Try edit this line
12
23
.get('/hello', () => 'Hello from Elysia!')
13
24
.listen(80)
@@ -73,7 +84,7 @@ let url = ref('/hello')
73
84
let response = ref (' Hello from Elysia!' )
74
85
75
86
let instance = new Elysia ()
76
- .get (' /' , () => ' Hello! ' )
87
+ .get (' /' , () => ({ some: " json " }) )
77
88
.get (' /hello' , () => ' Hello from Elysia!' ) as Elysia <any , any >
78
89
79
90
let editorError = ref (undefined as Error | undefined )
@@ -97,22 +108,37 @@ const execute = async () => {
97
108
response .value = x .headers
98
109
.get (' Content-Type' )
99
110
.includes (' application/json' )
100
- ? JSON .stringify (await x .json ())
111
+ ? JSON .stringify (await x .json (), null , 4 )
101
112
: await x .text ()
102
113
})
103
114
}
104
115
116
+ watch (isDark , (isDark ) => {
117
+ const editor = document .querySelector <HTMLElement >(' pre.elysia-editor' );
118
+
119
+ editor .innerHTML = highlighter .codeToHtml (
120
+ editor .innerText , {
121
+ theme: isDark ? ' github-dark' : ' github-light' ,
122
+ lang: ' javascript' ,
123
+ })
124
+ })
125
+
105
126
onMounted (() => {
106
127
const editor = document .querySelector <HTMLElement >(' pre.elysia-editor' )
107
128
129
+ editor .innerHTML = highlighter .codeToHtml (code , {
130
+ theme: isDark ? ' github-dark' : ' github-light' ,
131
+ lang: ' javascript' ,
132
+ })
133
+
108
134
function rehighlight(event ) {
109
135
const restore = saveCaretPosition (this )
110
136
111
- editor .innerHTML = highlight (
112
- event .currentTarget .innerText ,
113
- languages . typescript ,
114
- ' typescript '
115
- )
137
+ editor .innerHTML = highlighter . codeToHtml (
138
+ event .currentTarget .innerText , {
139
+ theme: isDark ? ' github-dark ' : ' github-light ' ,
140
+ lang: ' javascript ' ,
141
+ } )
116
142
117
143
restore ()
118
144
}
@@ -170,11 +196,9 @@ onMounted(() => {
170
196
<aside class =" flex flex-col md:flex-row justify-center items-center w-full max-w-6xl gap-8 my-8" >
171
197
<section class =" flex flex-col w-full h-96 border dark:border-slate-700 bg-white dark:bg-slate-800 rounded-2xl" >
172
198
<div class =" mockup-window flex relative w-full h-full shadow-xl" >
173
- <Prism
174
- class =" elysia-editor block !bg-transparent !text-base !font-mono rounded-xl w-full max-w-xl h-full !pt-0 !px-2 outline-none"
175
- language =" typescript" contenteditable =" true" >
176
- {{ code }}
177
- </Prism >
199
+ <pre class =" elysia-editor block !bg-transparent !text-base !font-mono rounded-xl w-full max-w-xl h-full !pt-0 !px-2 outline-none"
200
+ contenteditable =" true" >
201
+ </pre >
178
202
179
203
<footer v-if =" editorError"
180
204
class =" absolute bottom-0 flex flex-col w-full max-h-40 overflow-y-auto text-white font-medium px-4 py-2 bg-red-500" >
@@ -202,3 +226,14 @@ onMounted(() => {
202
226
</aside >
203
227
</article >
204
228
</template >
229
+
230
+ <style >
231
+ .elysia-editor > pre {
232
+ padding : 0 10px ;
233
+ background-color : rgba (0 , 0 , 0 , 0 ) !important ;
234
+ }
235
+
236
+ .elysia-editor > pre :focus-visible {
237
+ outline : none ;
238
+ }
239
+ </style >
0 commit comments