]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(sfc-playground): display vapor status
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 24 Jan 2024 14:14:12 +0000 (22:14 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Wed, 24 Jan 2024 14:14:12 +0000 (22:14 +0800)
packages/sfc-playground/package.json
packages/sfc-playground/src/App.vue
packages/sfc-playground/src/welcome.vue [new file with mode: 0644]
pnpm-lock.yaml

index c0cd7e10c42963b4db50cca88ff0786c19cc4a12..867333e1a09e884940ff4de2d755a02fa2a032c1 100644 (file)
@@ -13,7 +13,7 @@
     "vite": "^5.0.5"
   },
   "dependencies": {
-    "@vue/repl": "4.0.0-alpha.0",
+    "@vue/repl": "4.0.0-alpha.1",
     "file-saver": "^2.0.5",
     "jszip": "^3.10.1",
     "vue": "workspace:*"
index c01f05680ac2be0728c4497fcf545efc358b940f..e681cf3744b796244a03c7816686e029134e86e2 100644 (file)
@@ -8,10 +8,12 @@ import {
   mergeImportMap,
   File,
   StoreState,
+  ImportMap,
 } from '@vue/repl'
 import type Monaco from '@vue/repl/monaco-editor'
 import type CodeMirror from '@vue/repl/codemirror-editor'
 import { ref, watchEffect, onMounted, computed, shallowRef, watch } from 'vue'
+import welcomeSFC from './welcome.vue?raw'
 
 const EditorComponent = shallowRef<typeof Monaco | typeof CodeMirror>()
 
@@ -52,15 +54,20 @@ const {
     : `${location.origin}/src/vue-server-renderer-dev-proxy`,
 })
 
-const importMap = computed(() =>
-  mergeImportMap(vueImportMap.value, {
+const importMap = computed(() => {
+  const vapor = import.meta.env.PROD
+    ? `${location.origin}/vue-vapor.esm-browser.js`
+    : `${location.origin}/src/vue-vapor-dev-proxy`
+
+  const vaporImportMap: ImportMap = {
     imports: {
-      'vue/vapor': import.meta.env.PROD
-        ? `${location.origin}/vue-vapor.esm-browser.js`
-        : `${location.origin}/src/vue-vapor-dev-proxy`,
+      'vue/vapor': vapor,
     },
-  }),
-)
+  }
+  if (useVaporMode.value) vaporImportMap.imports!.vue = vapor
+
+  return mergeImportMap(vueImportMap.value, vaporImportMap)
+})
 
 let hash = location.hash.slice(1)
 if (hash.startsWith('__DEV__')) {
@@ -81,7 +88,6 @@ if (hash.startsWith('__VAPOR__')) {
 }
 
 const files: StoreState['files'] = ref(Object.create(null))
-const mainFile = ref('src/App.vue')
 
 // enable experimental features
 const sfcOptions = computed(
@@ -110,7 +116,9 @@ const store = useStore(
     vueVersion,
     builtinImportMap: importMap,
     sfcOptions,
-    mainFile,
+    template: ref({
+      welcomeSFC: welcomeSFC,
+    }),
   },
   hash,
 )
@@ -132,11 +140,13 @@ watch(
           `<div id="app"></div>`,
         true,
       )
-      mainFile.value = 'src/index.html'
-      store.activeFile = files.value['src/App.vue']
+      store.mainFile = 'src/index.html'
     } else if (files.value['src/index.html']?.hidden) {
       delete files.value['src/index.html']
-      mainFile.value = 'src/App.vue'
+      store.mainFile = 'src/App.vue'
+      if (store.activeFile.filename === 'src/index.html') {
+        store.activeFile = files.value['src/App.vue']
+      }
     }
   },
   { immediate: true },
diff --git a/packages/sfc-playground/src/welcome.vue b/packages/sfc-playground/src/welcome.vue
new file mode 100644 (file)
index 0000000..48b3c9d
--- /dev/null
@@ -0,0 +1,12 @@
+<script setup>
+import { ref, getCurrentInstance } from 'vue'
+
+const msg = ref('Hello World!')
+const isVapor = getCurrentInstance().vapor
+</script>
+
+<template>
+  <h1>{{ msg }}</h1>
+  <input v-model="msg" />
+  <b>VAPOR {{ isVapor ? 'ON' : 'OFF' }}</b>
+</template>
index 75dd6ed38f1ca18eecd4e686d35fc641c2f8c643..c7b9fdd9f2ce8fe5308eed29749a3b6dd6db4845 100644 (file)
@@ -371,8 +371,8 @@ importers:
   packages/sfc-playground:
     dependencies:
       '@vue/repl':
-        specifier: 4.0.0-alpha.0
-        version: 4.0.0-alpha.0
+        specifier: 4.0.0-alpha.1
+        version: 4.0.0-alpha.1
       file-saver:
         specifier: ^2.0.5
         version: 2.0.5
@@ -1637,8 +1637,8 @@ packages:
     engines: {node: '>= 0.12.0'}
     dev: true
 
-  /@vue/repl@4.0.0-alpha.0:
-    resolution: {integrity: sha512-kGgnon2yV1y0eKeWatys4by32XXCDSdq31Rwx0cd8xXAIK0GIL0AeSMCvVUrNE2ke8rFVYe6xMmpOd1iCcM0Zg==}
+  /@vue/repl@4.0.0-alpha.1:
+    resolution: {integrity: sha512-BK9D7AgpYAWVrtd7Kkc3CotU/ox8l+mPjsLgK16ZP+Ldj8jXPrJtzYQ2rTQNRJOxVSVx5acftDTLDLENFhQdDw==}
     dev: false
 
   /@zeit/schemas@2.29.0: