-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.vue
94 lines (76 loc) · 2.49 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<script setup lang="ts">
import type { OutputModes } from '@vue/repl'
import type { ShallowRef } from 'vue'
import { mergeImportMap, useStore, useVueImportMap } from '@vue/repl'
const showOutput = useRouteQuery<string, boolean>('showOutput', 'false', {
transform: stringToBooleanTransformer,
})
const outputMode = useRouteQuery<OutputModes, OutputModes>('outputMode', 'preview')
const ssr = useRouteQuery<string, boolean>('ssr', 'false', {
transform: stringToBooleanTransformer,
})
const prod = useRouteQuery<string, boolean>('prod', 'false', {
transform: stringToBooleanTransformer,
})
const hash = useRouteHash(undefined, { mode: 'replace' })
const {
importMap: builtinImportMap,
vueVersion,
productionMode,
} = useVueImportMap()
const injectedVueVersion = inject<ShallowRef<string>>('vueVersion', shallowRef<string>('latest'))
const vueuseVersion = useRouteQuery('vueuse', 'latest')
const vueUsePackages = [
'@vueuse/metadata',
'@vueuse/shared',
'@vueuse/core',
'@vueuse/integrations',
'@vueuse/math',
'@vueuse/rxjs',
]
function generateVueUseImportCDNs() {
return vueUsePackages.map((p) => {
return [p, `https://cdn.jsdelivr.net/npm/${p}@${vueuseVersion.value}/index.mjs`]
})
}
const importMap = computed(() => {
return mergeImportMap(builtinImportMap.value, {
imports: Object.fromEntries([...generateVueUseImportCDNs(), ['vue-demi', 'https://cdn.jsdelivr.net/npm/[email protected]/lib/index.mjs']]),
})
})
const { template } = useTemplate()
const store = useStore(
{
// pre-set import map
builtinImportMap: importMap,
vueVersion,
// starts on the output pane (mobile only) if the URL has a showOutput query
showOutput,
// starts on a different tab on the output pane if the URL has a outputMode query
// and default to the "preview" tab
outputMode,
template,
},
// initialize repl with previously serialized state
hash.value ?? undefined,
)
injectedVueVersion.value = vueVersion.value ?? 'latest'
// persist state to URL hash
watchEffect(() => hash.value = store.serialize())
watch(() => injectedVueVersion.value, (newVersion) => {
vueVersion.value = newVersion
})
watch(() => prod.value, (newProd) => {
productionMode.value = newProd
}, { immediate: true })
</script>
<template>
<ClientOnly>
<ReplEditor :ssr="ssr" :store="store" />
<template #fallback>
<div class="flex w-full h-full justify-center items-center px-12">
<UProgress animation="swing" />
</div>
</template>
</ClientOnly>
</template>