Skip to content

Commit be4ead6

Browse files
committed
feat: add readonly prop to Repl
1 parent 9bd878d commit be4ead6

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/Repl.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface Props {
1919
sfcOptions?: SFCOptions
2020
layout?: 'horizontal' | 'vertical'
2121
ssr?: boolean
22+
readonly?: boolean
2223
previewOptions?: {
2324
headHTML?: string
2425
bodyHTML?: string
@@ -38,6 +39,7 @@ const props = withDefaults(defineProps<Props>(), {
3839
showTsConfig: true,
3940
clearConsole: true,
4041
ssr: false,
42+
readonly: false,
4143
previewOptions: () => ({
4244
headHTML: '',
4345
bodyHTML: '',
@@ -79,6 +81,7 @@ provide('tsconfig', toRef(props, 'showTsConfig'))
7981
provide('clear-console', toRef(props, 'clearConsole'))
8082
provide('preview-options', props.previewOptions)
8183
provide('theme', toRef(props, 'theme'))
84+
provide('readonly', toRef(props, 'readonly'))
8285
/**
8386
* Reload the preview iframe
8487
*/
@@ -128,9 +131,8 @@ defineExpose({ reload })
128131
margin: 0;
129132
overflow: hidden;
130133
font-size: 13px;
131-
font-family:
132-
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
133-
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
134+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
135+
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
134136
background-color: var(--bg-soft);
135137
}
136138
</style>

src/editor/EditorContainer.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ const props = defineProps<{
1616
}>()
1717
1818
const store = inject('store') as Store
19+
const readonly = inject('readonly', ref(false))
1920
const showMessage = ref((getItem(SHOW_ERROR_KEY) ?? 'true') === 'true')
2021
store.state.wordWrap = (getItem(TOGGLE_WRAP_KEY) ?? 'false') === 'true'
2122
2223
const onChange = debounce((code: string, filename: string) => {
24+
if (readonly.value) return
2325
store.state.files[filename].code = code
2426
}, 250)
2527
@@ -50,6 +52,7 @@ watch(
5052
@change="onChange($event, store.state.activeFile.filename)"
5153
:value="store.state.activeFile.code"
5254
:filename="store.state.activeFile.filename"
55+
:readonly="readonly"
5356
/>
5457
<Message v-show="showMessage" :err="store.state.errors[0]" />
5558
<MessageToggle v-model="showMessage" />

src/editor/FileExplorer.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<template v-slot:append>
1414
<v-btn
15+
v-if="!readonly"
1516
variant="text"
1617
size="small"
1718
:append-icon="`svg:${mdiFilePlusOutline}`"
@@ -50,6 +51,7 @@
5051

5152
<template v-slot:append>
5253
<v-icon-btn
54+
v-if="!readonly"
5355
icon="$close"
5456
size="26"
5557
icon-size="14"
@@ -60,7 +62,7 @@
6062
</v-list-item>
6163

6264
<v-text-field
63-
v-if="pending"
65+
v-if="pending && !readonly"
6466
v-model="pendingFilename"
6567
density="compact"
6668
hide-details
@@ -117,7 +119,7 @@
117119

118120
<script setup lang="ts">
119121
import type { Store } from 'src/store'
120-
import { inject } from 'vue'
122+
import { inject, ref } from 'vue'
121123
import { useFileSelector } from '../composables/useFileSelector'
122124
import { VIconBtn } from 'vuetify/labs/components'
123125
import {
@@ -129,6 +131,7 @@ import {
129131
} from '@mdi/js'
130132
131133
const store = inject('store') as Store
134+
const readonly = inject('readonly', ref(false))
132135
133136
const {
134137
activeFile,

src/editor/FileSelector.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</template>
3434
<span>{{ stripSrcPrefix(file) }}</span>
3535
<v-icon-btn
36-
v-if="recentFiles.length > 1"
36+
v-if="recentFiles.length > 1 && !readonly"
3737
icon="$close"
3838
size="20px"
3939
icon-size="15px"
@@ -57,6 +57,7 @@ import { useDisplay } from 'vuetify'
5757
const MAX_RECENT_FILES = 10
5858
5959
const store = inject('store') as Store
60+
const readonly = inject('readonly', ref(false))
6061
const { mdAndDown } = useDisplay()
6162
const { activeFile, stripSrcPrefix, getFileIcon, getFileIconColor } =
6263
useFileSelector()

0 commit comments

Comments
 (0)