diff --git a/packages/sfc-playground/src/App.vue b/packages/sfc-playground/src/App.vue index cf4424ad6..6a0047d74 100644 --- a/packages/sfc-playground/src/App.vue +++ b/packages/sfc-playground/src/App.vue @@ -24,7 +24,7 @@ body { font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; - color:var(--base); + color: var(--base); margin: 0; background-color: #f8f8f8; --base: #444; diff --git a/packages/sfc-playground/src/Header.vue b/packages/sfc-playground/src/Header.vue index a2a9f8843..1a74ceb24 100644 --- a/packages/sfc-playground/src/Header.vue +++ b/packages/sfc-playground/src/Header.vue @@ -14,7 +14,7 @@
  • v{{ version }}
  • -
  • This Commit ({{ commit }})
  • +
  • This Commit ({{ currentCommit }})
  • Commits History
  • @@ -51,8 +51,8 @@ import { downloadProject } from './download/download' import { setVersion, resetVersion } from './sfcCompiler' import { ref, onMounted } from 'vue' -const commit = __COMMIT__ -const activeVersion = ref(`@${commit}`) +const currentCommit = __COMMIT__ +const activeVersion = ref(`@${currentCommit}`) const publishedVersions = ref() const expanded = ref(false) @@ -72,7 +72,7 @@ async function setVueVersion(v: string) { function resetVueVersion() { resetVersion() - activeVersion.value = `@${commit}` + activeVersion.value = `@${currentCommit}` expanded.value = false } diff --git a/packages/sfc-playground/src/editor/Editor.vue b/packages/sfc-playground/src/editor/Editor.vue index 86f4f6734..481450289 100644 --- a/packages/sfc-playground/src/editor/Editor.vue +++ b/packages/sfc-playground/src/editor/Editor.vue @@ -20,7 +20,7 @@ const onChange = debounce((code: string) => { const activeCode = ref(store.activeFile.code) const activeMode = computed( - () => (store.activeFilename.endsWith('.js') ? 'javascript' : 'htmlmixed') + () => (store.activeFilename.endsWith('.vue') ? 'htmlmixed' : 'javascript') ) watch( diff --git a/packages/sfc-playground/src/editor/FileSelector.vue b/packages/sfc-playground/src/editor/FileSelector.vue index 639b0ec18..e731e7e32 100644 --- a/packages/sfc-playground/src/editor/FileSelector.vue +++ b/packages/sfc-playground/src/editor/FileSelector.vue @@ -45,8 +45,12 @@ function focus({ el }: VNode) { function doneAddFile() { const filename = pendingFilename.value - if (!filename.endsWith('.vue') && !filename.endsWith('.js')) { - store.errors = [`Playground only supports .vue or .js files.`] + if ( + !filename.endsWith('.vue') && + !filename.endsWith('.js') && + filename !== 'import-map.json' + ) { + store.errors = [`Playground only supports *.vue, *.js files or import-map.json.`] return } diff --git a/packages/sfc-playground/src/output/Preview.vue b/packages/sfc-playground/src/output/Preview.vue index 637b618eb..52b35c1fc 100644 --- a/packages/sfc-playground/src/output/Preview.vue +++ b/packages/sfc-playground/src/output/Preview.vue @@ -1,60 +1,105 @@ - + - window.__export__ = (mod, key, get) => { - Object.defineProperty(mod, key, { - enumerable: true, - configurable: true, - get - }) - } + diff --git a/packages/sfc-playground/src/sfcCompiler.ts b/packages/sfc-playground/src/sfcCompiler.ts index dc5866328..d77a6e31c 100644 --- a/packages/sfc-playground/src/sfcCompiler.ts +++ b/packages/sfc-playground/src/sfcCompiler.ts @@ -1,6 +1,7 @@ import { store, File } from './store' import { SFCDescriptor, BindingMetadata } from '@vue/compiler-sfc' import * as defaultCompiler from '@vue/compiler-sfc' +import { ref } from 'vue' export const MAIN_FILE = 'App.vue' export const COMP_IDENTIFIER = `__sfc__` @@ -16,23 +17,23 @@ const defaultVueUrl = import.meta.env.PROD ? '/vue.runtime.esm-browser.js' // to be copied on build : '/src/vue-dev-proxy' -export let SANDBOX_VUE_URL = defaultVueUrl +export const vueRuntimeUrl = ref(defaultVueUrl) export async function setVersion(version: string) { const compilerUrl = `https://unpkg.com/@vue/compiler-sfc@${version}/dist/compiler-sfc.esm-browser.js` - const runtimeUrl = `https://cdn.skypack.dev/@vue/runtime-dom@${version}` + const runtimeUrl = `https://unpkg.com/@vue/runtime-dom@${version}/dist/runtime-dom.esm-browser.js` const [compiler] = await Promise.all([ import(/* @vite-ignore */ compilerUrl), import(/* @vite-ignore */ runtimeUrl) ]) SFCCompiler = compiler - SANDBOX_VUE_URL = runtimeUrl + vueRuntimeUrl.value = runtimeUrl console.info(`Now using Vue version: ${version}`) } export function resetVersion() { SFCCompiler = defaultCompiler - SANDBOX_VUE_URL = defaultVueUrl + vueRuntimeUrl.value = defaultVueUrl } export async function compileFile({ filename, code, compiled }: File) { @@ -41,7 +42,7 @@ export async function compileFile({ filename, code, compiled }: File) { return } - if (filename.endsWith('.js')) { + if (!filename.endsWith('.vue')) { compiled.js = compiled.ssr = code store.errors = [] return diff --git a/packages/sfc-playground/src/store.ts b/packages/sfc-playground/src/store.ts index 320f6cd30..22080ea10 100644 --- a/packages/sfc-playground/src/store.ts +++ b/packages/sfc-playground/src/store.ts @@ -30,6 +30,7 @@ interface Store { files: Record activeFilename: string readonly activeFile: File + readonly importMap: string | undefined errors: (string | Error)[] } @@ -53,6 +54,10 @@ export const store: Store = reactive({ get activeFile() { return store.files[store.activeFilename] }, + get importMap() { + const file = store.files['import-map.json'] + return file && file.code + }, errors: [] }) @@ -81,7 +86,17 @@ export function setActive(filename: string) { } export function addFile(filename: string) { - store.files[filename] = new File(filename) + const file = (store.files[filename] = new File(filename)) + + if (filename === 'import-map.json') { + file.code = ` +{ + "imports": { + + } +}`.trim() + } + setActive(filename) }