Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SplitPane from './SplitPane.vue'
import Output from './output/Output.vue'
import { Store, ReplStore, SFCOptions } from './store'
import { provide, toRef } from 'vue'
import { provide, ref, toRef } from 'vue'
import type { EditorComponentType } from './editor/types'
import EditorContainer from './editor/EditorContainer.vue'

Expand Down Expand Up @@ -47,6 +47,7 @@ if (!props.editor) {
throw new Error('The "editor" prop is now required.')
}

const outputRef = ref<InstanceType<typeof Output>>()
const { store } = props
const sfcOptions = (store.options = props.sfcOptions || {})
if (!sfcOptions.script) {
Expand All @@ -71,6 +72,15 @@ provide('autoresize', props.autoResize)
provide('import-map', toRef(props, 'showImportMap'))
provide('clear-console', toRef(props, 'clearConsole'))
provide('preview-options', props.previewOptions)

/**
* Reload the preview iframe
*/
function reload() {
outputRef.value?.reload()
}

defineExpose({ reload })
</script>

<template>
Expand All @@ -81,6 +91,7 @@ provide('preview-options', props.previewOptions)
</template>
<template #right>
<Output
ref="outputRef"
:editorComponent="editor"
:showCompileOutput="props.showCompileOutput"
:ssr="!!props.ssr"
Expand Down
9 changes: 8 additions & 1 deletion src/output/Output.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const props = defineProps<{
}>()

const store = inject('store') as Store
const previewRef = ref<InstanceType<typeof Preview>>()
const modes = computed(() =>
props.showCompileOutput
? (['preview', 'js', 'css', 'ssr'] as const)
Expand All @@ -23,6 +24,12 @@ const mode = ref<OutputModes>(
? (store.initialOutputMode as OutputModes)
: 'preview'
)

function reload() {
previewRef.value?.reload()
}

defineExpose({ reload })
</script>

<template>
Expand All @@ -37,7 +44,7 @@ const mode = ref<OutputModes>(
</div>

<div class="output-container">
<Preview :show="mode === 'preview'" :ssr="ssr" />
<Preview ref="previewRef" :show="mode === 'preview'" :ssr="ssr" />
<props.editorComponent
v-if="mode !== 'preview'"
readonly
Expand Down
9 changes: 9 additions & 0 deletions src/output/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ async function updatePreview() {
runtimeError.value = (e as Error).message
}
}

/**
* Reload the preview iframe
*/
function reload() {
sandbox.contentWindow?.location.reload()
}

defineExpose({ reload })
</script>

<template>
Expand Down