Skip to content

Commit

Permalink
feat: add more customization options (#274)
Browse files Browse the repository at this point in the history
Co-authored-by: wangleping <wangleping@xiaohongshu.com>
  • Loading branch information
lecepin and wangleping authored Aug 22, 2024
1 parent c6f58c7 commit c73b786
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export interface Props {
importCode?: string
useCode?: string
}
showRuntimeError?: boolean
showRuntimeWarning?: boolean
}
editorOptions?: {
ShowErrorText?: string
}
}
Expand All @@ -51,8 +56,13 @@ const props = withDefaults(defineProps<Props>(), {
importCode: '',
useCode: '',
},
showRuntimeError: true,
showRuntimeWarning: true,
}),
layout: 'horizontal',
editorOptions: () => ({
ShowErrorText: 'Show Error',
}),
})
if (!props.editor) {
Expand All @@ -73,6 +83,7 @@ provide('import-map', toRef(props, 'showImportMap'))
provide('tsconfig', toRef(props, 'showTsConfig'))
provide('clear-console', toRef(props, 'clearConsole'))
provide('preview-options', props.previewOptions)
provide('editor-options', props.editorOptions)
provide('theme', toRef(props, 'theme'))
provide('preview-theme', toRef(props, 'previewTheme'))
provide('preview-ref', () => outputRef.value?.previewRef?.container)
Expand Down
6 changes: 5 additions & 1 deletion src/editor/MessageToggle.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<script setup lang="ts">
import { inject } from 'vue'
import type { Props } from '../Repl.vue'
const editorOptions = inject<Props['editorOptions']>('editor-options')
const visible = defineModel<boolean>()
</script>

<template>
<div class="wrapper" @click="visible = !visible">
<span>Show Error</span>
<span>{{ editorOptions?.ShowErrorText }}</span>
<div class="toggle" :class="[{ active: modelValue }]">
<div class="indicator" />
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/output/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ defineExpose({ reload, container })
class="iframe-container"
:class="{ [theme]: previewTheme }"
/>
<Message :err="runtimeError" />
<Message v-if="!runtimeError" :warn="runtimeWarning" />
<Message :err="runtimeError && previewOptions?.showRuntimeError" />
<Message v-if="!runtimeError && previewOptions?.showRuntimeWarning" :warn="runtimeWarning" />
</template>
<style scoped>
Expand Down

0 comments on commit c73b786

Please sign in to comment.