Skip to content

Commit 7a051ec

Browse files
committed
feat(Preview): add bodyStyle & appStyle props
1 parent 31ecf50 commit 7a051ec

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/output/Preview.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import { compileModulesForPreview } from './moduleCompiler'
1616
import { Store, importMapFile } from '../store'
1717
import { Props } from '../Repl.vue'
1818
19-
const props = defineProps<{ show: boolean; ssr: boolean }>()
19+
const props = defineProps<{
20+
show: boolean
21+
ssr: boolean
22+
bodyStyle?: CSSStyleDeclaration
23+
appStyle?: CSSStyleDeclaration
24+
}>()
2025
export type UpdateFlag = 'UPDATING' | 'SUCCESS' | 'FAILURE'
2126
const emits = defineEmits<{
2227
(e: 'update-preview', flag: UpdateFlag): UpdateFlag
@@ -270,6 +275,23 @@ async function updatePreview() {
270275
runtimeError.value = (e as Error).message
271276
emits('update-preview', 'FAILURE')
272277
}
278+
279+
if (sandbox.contentWindow?.document.body && props.bodyStyle) {
280+
for (const key in props.bodyStyle) {
281+
sandbox.contentWindow.document.body.style[key] = props.bodyStyle[key]
282+
}
283+
}
284+
285+
if (props.appStyle) {
286+
const appEl = sandbox.contentWindow?.document.body.querySelector(
287+
'#app'
288+
) as HTMLElement
289+
if (appEl) {
290+
for (const key in props.appStyle) {
291+
appEl.style[key] = props.appStyle[key]
292+
}
293+
}
294+
}
273295
}
274296
</script>
275297

0 commit comments

Comments
 (0)