@@ -14,11 +14,15 @@ import srcdoc from './srcdoc.html?raw'
14
14
import { PreviewProxy } from ' ./PreviewProxy'
15
15
import { compileModulesForPreview } from ' ./moduleCompiler'
16
16
import { Store } from ' ../store'
17
+ import { Props } from ' ../Repl.vue'
17
18
18
19
const props = defineProps <{ show: boolean ; ssr: boolean }>()
19
20
20
21
const store = inject (' store' ) as Store
21
22
const clearConsole = inject (' clear-console' ) as Ref <boolean >
23
+
24
+ const previewOptions = inject (' preview-options' ) as Props [' previewOptions' ]
25
+
22
26
const container = ref ()
23
27
const runtimeError = ref ()
24
28
const runtimeWarning = ref ()
@@ -85,10 +89,12 @@ function createSandbox() {
85
89
if (! importMap .imports .vue ) {
86
90
importMap .imports .vue = store .state .vueRuntimeURL
87
91
}
88
- const sandboxSrc = srcdoc .replace (
89
- / <!--IMPORT_MAP-->/ ,
90
- JSON .stringify (importMap )
91
- )
92
+ const sandboxSrc = srcdoc
93
+ .replace (/ <!--IMPORT_MAP-->/ , JSON .stringify (importMap ))
94
+ .replace (
95
+ / <!-- PREVIEW-OPTIONS-HEAD-HTML -->/ ,
96
+ previewOptions ?.headHTML || ' '
97
+ )
92
98
sandbox .srcdoc = sandboxSrc
93
99
container .value .appendChild (sandbox )
94
100
@@ -196,7 +202,9 @@ async function updatePreview() {
196
202
}
197
203
app.config.warnHandler = () => {}
198
204
window.__ssr_promise__ = _renderToString(app).then(html => {
199
- document.body.innerHTML = '<div id="app">' + html + '</div>'
205
+ document.body.innerHTML = '<div id="app">' + html + '</div>' + \` ${
206
+ previewOptions ?.bodyHTML || ' '
207
+ }\`
200
208
}).catch(err => {
201
209
console.error("SSR Error", err)
202
210
})
@@ -213,9 +221,13 @@ async function updatePreview() {
213
221
)
214
222
215
223
const codeToEval = [
216
- ` window.__modules__ = {}\n window.__css__ = ''\n ` +
217
- ` if (window.__app__) window.__app__.unmount()\n ` +
218
- (isSSR ? ` ` : ` document.body.innerHTML = '<div id="app"></div>' ` ),
224
+ ` window.__modules__ = {};window.__css__ = ''; ` +
225
+ ` if (window.__app__) window.__app__.unmount(); ` +
226
+ (isSSR
227
+ ? ` `
228
+ : ` document.body.innerHTML = '<div id="app"></div>' + \` ${
229
+ previewOptions ?.bodyHTML || ' '
230
+ }\` ` ),
219
231
... modules ,
220
232
` document.getElementById('__sfc-styles').innerHTML = window.__css__ `
221
233
]
@@ -226,6 +238,7 @@ async function updatePreview() {
226
238
` import { ${
227
239
isSSR ? ` createSSRApp ` : ` createApp `
228
240
} as _createApp } from "vue"
241
+ ${previewOptions ?.customCode ?.importCode || ' ' }
229
242
const _mount = () => {
230
243
const AppComponent = __modules__["${mainFile }"].default
231
244
AppComponent.name = 'Repl'
@@ -234,6 +247,7 @@ async function updatePreview() {
234
247
app.config.unwrapInjectedRef = true
235
248
}
236
249
app.config.errorHandler = e => console.error(e)
250
+ ${previewOptions ?.customCode ?.useCode || ' ' }
237
251
app.mount('#app')
238
252
}
239
253
if (window.__ssr_promise__) {
0 commit comments