Skip to content

Commit

Permalink
feat: add template for new file
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 19, 2023
1 parent df1a0fc commit 9a0be1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ sfcOptions.script.fs = {
store.init()
const editorSlotName = computed(() => props.layoutReverse ? 'right' : 'left')
const outputSlotName = computed(() => props.layoutReverse ? 'left' : 'right')
const editorSlotName = computed(() => (props.layoutReverse ? 'right' : 'left'))
const outputSlotName = computed(() => (props.layoutReverse ? 'left' : 'right'))
provide('store', store)
provide('autoresize', props.autoResize)
Expand Down
17 changes: 3 additions & 14 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@ import {
} from 'vue/compiler-sfc'
import { OutputModes } from './output/types'
import type { editor } from 'monaco-editor-core'
import welcomeCode from './template/welcome.vue?raw'
import newFileCode from './template/new-file.vue?raw'

const defaultMainFile = 'src/App.vue'

export const importMapFile = 'import-map.json'
export const tsconfigFile = 'tsconfig.json'

const welcomeCode = `
<script setup>
import { ref } from 'vue'
const msg = ref('Hello World!')
</script>
<template>
<h1>{{ msg }}</h1>
<input v-model="msg">
</template>
`.trim()

const tsconfig = {
compilerOptions: {
allowJs: true,
Expand Down Expand Up @@ -254,7 +243,7 @@ export class ReplStore implements Store {
addFile(fileOrFilename: string | File): void {
const file =
typeof fileOrFilename === 'string'
? new File(fileOrFilename)
? new File(fileOrFilename, newFileCode)
: fileOrFilename
this.state.files[file.filename] = file
if (!file.hidden) this.setActive(file.filename)
Expand Down
7 changes: 7 additions & 0 deletions src/template/new-file.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup></script>

<template>
<div>
<slot />
</div>
</template>
10 changes: 10 additions & 0 deletions src/template/welcome.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup>
import { ref } from 'vue'
const msg = ref('Hello World!')
</script>

<template>
<h1>{{ msg }}</h1>
<input v-model="msg" />
</template>

0 comments on commit 9a0be1d

Please sign in to comment.