@@ -14,11 +14,15 @@ import srcdoc from './srcdoc.html?raw'
1414import { PreviewProxy } from ' ./PreviewProxy'
1515import { compileModulesForPreview } from ' ./moduleCompiler'
1616import { Store } from ' ../store'
17+ import { Props } from ' ../Repl.vue'
1718
1819const props = defineProps <{ show: boolean ; ssr: boolean }>()
1920
2021const store = inject (' store' ) as Store
2122const clearConsole = inject (' clear-console' ) as Ref <boolean >
23+
24+ const previewOptions = inject (' preview-options' ) as Props [' previewOptions' ]
25+
2226const container = ref ()
2327const runtimeError = ref ()
2428const runtimeWarning = ref ()
@@ -85,10 +89,12 @@ function createSandbox() {
8589 if (! importMap .imports .vue ) {
8690 importMap .imports .vue = store .state .vueRuntimeURL
8791 }
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+ )
9298 sandbox .srcdoc = sandboxSrc
9399 container .value .appendChild (sandbox )
94100
@@ -196,7 +202,9 @@ async function updatePreview() {
196202 }
197203 app.config.warnHandler = () => {}
198204 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+ }\`
200208 }).catch(err => {
201209 console.error("SSR Error", err)
202210 })
@@ -213,9 +221,13 @@ async function updatePreview() {
213221 )
214222
215223 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+ }\` ` ),
219231 ... modules ,
220232 ` document.getElementById('__sfc-styles').innerHTML = window.__css__ `
221233 ]
@@ -226,6 +238,7 @@ async function updatePreview() {
226238 ` import { ${
227239 isSSR ? ` createSSRApp ` : ` createApp `
228240 } as _createApp } from "vue"
241+ ${previewOptions ?.customCode ?.importCode || ' ' }
229242 const _mount = () => {
230243 const AppComponent = __modules__["${mainFile }"].default
231244 AppComponent.name = 'Repl'
@@ -234,6 +247,7 @@ async function updatePreview() {
234247 app.config.unwrapInjectedRef = true
235248 }
236249 app.config.errorHandler = e => console.error(e)
250+ ${previewOptions ?.customCode ?.useCode || ' ' }
237251 app.mount('#app')
238252 }
239253 if (window.__ssr_promise__) {
0 commit comments