11<script setup lang="ts">
22import type { PreviewUpdateFlag , Store } from ' ../src'
3- import { MonacoEditor , Preview , ReplStore , defaultMainFile } from ' ../src'
4- import { computed , onMounted , provide , ref } from ' vue'
3+ import {
4+ ExtendEditorContainer ,
5+ Preview ,
6+ ReplStore ,
7+ defaultMainFile ,
8+ importMapFile ,
9+ } from ' ../src'
10+ import { computed , onMounted , provide , ref , toRef } from ' vue'
511import { useClipboard , useDebounceFn , useElementHover } from ' @vueuse/core'
612import Copy from ' ./icons/Copy.vue'
713import Copied from ' ./icons/Copied.vue'
@@ -27,6 +33,8 @@ export interface Props {
2733 useCode? : string
2834 }
2935 }
36+ importMap? : Record <string , string > | string
37+ theme? : ' dark' | ' light'
3038}
3139
3240const props = withDefaults (defineProps <Props >(), {
@@ -44,6 +52,7 @@ const props = withDefaults(defineProps<Props>(), {
4452 useCode: ' ' ,
4553 },
4654 }),
55+ theme: ' light' ,
4756})
4857
4958const { store } = props
@@ -61,20 +70,22 @@ const msg = ref('vite-plugin-vue-preview')
6170</template>
6271` .trim ()
6372
64- if ( ! props . code ) {
65- store . setFiles ({
66- [defaultMainFile ]: welcomeCode ,
67- } )
68- } else if ( props .encode ) {
69- store . setFiles ({
70- [ defaultMainFile ]: decodeURIComponent (props .code ),
71- })
72- } else {
73- store . setFiles ({
74- [ defaultMainFile ] : props .code ,
75- } )
73+ const files : Record < string , string > = {}
74+
75+ if ( ! props . code ) files [defaultMainFile ] = welcomeCode
76+ else if ( props . encode ) files [ defaultMainFile ] = decodeURIComponent ( props . code )
77+ else files [ defaultMainFile ] = props .code
78+
79+ if (props .importMap ) {
80+ const importMap =
81+ typeof props . importMap === ' string '
82+ ? JSON . parse ( decodeURIComponent ( props . importMap ))
83+ : props .importMap
84+ files [ importMapFile ] = JSON . stringify ({ imports: importMap }, null , 2 )
7685}
7786
87+ store .setFiles (files )
88+
7889onMounted (() => {
7990 if (props .clearConsole )
8091 // eslint-disable-next-line no-console
@@ -96,6 +107,7 @@ provide('store', store)
96107provide (' autoresize' , props .autoResize )
97108provide (' clear-console' , props .clearConsole )
98109provide (' preview-options' , props .previewOptions )
110+ provide (' theme' , toRef (props , ' theme' ))
99111
100112const { copy, copied } = useClipboard ({
101113 source: store .state .activeFile .code ,
@@ -159,11 +171,7 @@ const isHover = useElementHover(vuePreviewContainerRef)
159171 </div >
160172 </Transition >
161173 </div >
162- <MonacoEditor
163- :value =" store.state.activeFile.code"
164- :filename =" store.state.activeFile.filename"
165- @change =" onChange"
166- />
174+ <ExtendEditorContainer />
167175 </div >
168176</template >
169177
@@ -253,6 +261,10 @@ const isHover = useElementHover(vuePreviewContainerRef)
253261 max-height : v-bind (' maxHeightForCode' );
254262 transition : max-height 0.3s ;
255263 }
264+
265+ .editor-container {
266+ height : 400px ;
267+ }
256268}
257269
258270.vue-preview-slide-down-enter-active ,
0 commit comments