Skip to content

Commit cf070f6

Browse files
committed
add more configuration props
1 parent d4caaf4 commit cf070f6

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

src/Repl.vue

+15-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ import Output from './output/Output.vue'
55
import { ReplStore } from './store'
66
import { provide } from 'vue'
77
8-
const props = withDefaults(
9-
defineProps<{
10-
store?: ReplStore
11-
showCompileOutput?: boolean
12-
}>(),
13-
{
14-
store: () => new ReplStore(),
15-
showCompileOutput: false
16-
}
17-
)
8+
interface Props {
9+
store?: ReplStore
10+
autoResize?: boolean
11+
showCompileOutput?: boolean
12+
showImportMap?: boolean
13+
}
14+
15+
const props = withDefaults(defineProps<Props>(), {
16+
store: () => new ReplStore(),
17+
autoResize: true,
18+
showCompileOutput: true,
19+
showImportMap: true
20+
})
1821
1922
provide('store', props.store)
23+
provide('autoresize', props.autoResize)
24+
provide('import-map', props.showImportMap)
2025
</script>
2126

2227
<template>

src/codemirror/CodeMirror.vue

+20-15
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,27 @@
33
</template>
44

55
<script setup lang="ts">
6-
import { ref, onMounted, watchEffect } from 'vue'
6+
import { ref, onMounted, watchEffect, inject } from 'vue'
7+
import { debounce } from '../utils'
78
import CodeMirror from './codemirror'
89
9-
const el = ref()
10+
interface Props {
11+
mode?: string
12+
value?: string
13+
readonly?: boolean
14+
}
1015
11-
const props = defineProps({
12-
mode: {
13-
type: String,
14-
default: 'htmlmixed'
15-
},
16-
value: {
17-
type: String,
18-
default: ''
19-
},
20-
readonly: {
21-
type: Boolean,
22-
default: false
23-
}
16+
const props = withDefaults(defineProps<Props>(), {
17+
mode: 'htmlmixed',
18+
value: '',
19+
readonly: false
2420
})
2521
2622
const emit = defineEmits<(e: 'change', value: string) => void>()
2723
24+
const el = ref()
25+
const needAutoResize = inject('autoresize')
26+
2827
onMounted(() => {
2928
const addonOptions = {
3029
autoCloseBrackets: true,
@@ -57,6 +56,12 @@ onMounted(() => {
5756
setTimeout(() => {
5857
editor.refresh()
5958
}, 50)
59+
60+
if (needAutoResize) {
61+
window.addEventListener('resize', debounce(() => {
62+
editor.refresh()
63+
}))
64+
}
6065
})
6166
</script>
6267

src/editor/FileSelector.vue

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const store = inject('store') as ReplStore
77
const pending = ref(false)
88
const pendingFilename = ref('Comp.vue')
99
const importMapFile = 'import-map.json'
10+
const showImportMap = inject<boolean>('import-map')
1011
const files = computed(() =>
1112
Object.keys(store.state.files).filter((f) => f !== importMapFile)
1213
)
@@ -70,6 +71,7 @@ function doneAddFile() {
7071
</div>
7172
<button class="add" @click="startAddFile">+</button>
7273
<div
74+
v-if="showImportMap"
7375
class="file import-map"
7476
:class="{ active: store.state.activeFilename === importMapFile }"
7577
@click="store.setActive(importMapFile)"

test/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createApp, h, watchEffect } from 'vue'
22
import { Repl, ReplStore } from '../src'
3-
43
;(window as any).process = { env: {} }
54

65
const App = {
@@ -19,7 +18,8 @@ const App = {
1918
return () =>
2019
h(Repl, {
2120
store,
22-
showCompileOutput: true
21+
// showCompileOutput: false,
22+
// showImportMap: false
2323
})
2424
}
2525
}

0 commit comments

Comments
 (0)