2021-03-29 11:36:36 +08:00
|
|
|
<script setup lang="ts">
|
2021-03-29 11:48:01 +08:00
|
|
|
import { downloadProject } from './download/download'
|
2021-03-31 10:00:46 +08:00
|
|
|
import { ref, onMounted } from 'vue'
|
2021-09-17 02:23:09 +08:00
|
|
|
import Sun from './icons/Sun.vue'
|
|
|
|
import Moon from './icons/Moon.vue'
|
|
|
|
import Share from './icons/Share.vue'
|
|
|
|
import Download from './icons/Download.vue'
|
2021-12-12 10:01:48 +08:00
|
|
|
import GitHub from './icons/GitHub.vue'
|
2021-03-29 11:36:36 +08:00
|
|
|
|
2021-09-07 06:02:27 +08:00
|
|
|
// @ts-ignore
|
2022-05-17 12:10:29 +08:00
|
|
|
const props = defineProps(['store', 'dev'])
|
|
|
|
const { store } = props
|
2021-09-07 06:02:27 +08:00
|
|
|
|
2021-04-01 01:31:00 +08:00
|
|
|
const currentCommit = __COMMIT__
|
|
|
|
const activeVersion = ref(`@${currentCommit}`)
|
2021-03-31 10:00:46 +08:00
|
|
|
const publishedVersions = ref<string[]>()
|
|
|
|
const expanded = ref(false)
|
|
|
|
|
|
|
|
async function toggle() {
|
|
|
|
expanded.value = !expanded.value
|
|
|
|
if (!publishedVersions.value) {
|
|
|
|
publishedVersions.value = await fetchVersions()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function setVueVersion(v: string) {
|
|
|
|
activeVersion.value = `loading...`
|
2021-09-07 06:02:27 +08:00
|
|
|
await store.setVueVersion(v)
|
2021-03-31 10:00:46 +08:00
|
|
|
activeVersion.value = `v${v}`
|
|
|
|
expanded.value = false
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetVueVersion() {
|
2021-09-07 06:02:27 +08:00
|
|
|
store.resetVueVersion()
|
2021-04-01 01:31:00 +08:00
|
|
|
activeVersion.value = `@${currentCommit}`
|
2021-03-31 10:00:46 +08:00
|
|
|
expanded.value = false
|
|
|
|
}
|
2021-03-29 14:07:04 +08:00
|
|
|
|
2021-03-29 22:54:32 +08:00
|
|
|
async function copyLink() {
|
|
|
|
await navigator.clipboard.writeText(location.href)
|
2021-03-29 11:36:36 +08:00
|
|
|
alert('Sharable URL has been copied to clipboard.')
|
|
|
|
}
|
2021-03-31 10:00:46 +08:00
|
|
|
|
2021-09-17 02:23:09 +08:00
|
|
|
function toggleDark() {
|
|
|
|
const cls = document.documentElement.classList
|
|
|
|
cls.toggle('dark')
|
|
|
|
localStorage.setItem(
|
|
|
|
'vue-sfc-playground-prefer-dark',
|
|
|
|
String(cls.contains('dark'))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-03-31 10:00:46 +08:00
|
|
|
onMounted(async () => {
|
|
|
|
window.addEventListener('click', () => {
|
|
|
|
expanded.value = false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
async function fetchVersions(): Promise<string[]> {
|
|
|
|
const res = await fetch(
|
2022-01-18 16:43:59 +08:00
|
|
|
`https://api.github.com/repos/vuejs/core/releases?per_page=100`
|
2021-03-31 10:00:46 +08:00
|
|
|
)
|
|
|
|
const releases: any[] = await res.json()
|
2021-08-24 00:21:17 +08:00
|
|
|
const versions = releases.map(r =>
|
2021-10-09 00:31:34 +08:00
|
|
|
/^v/.test(r.tag_name) ? r.tag_name.slice(1) : r.tag_name
|
2021-03-31 10:00:46 +08:00
|
|
|
)
|
2021-08-24 02:23:46 +08:00
|
|
|
// if the latest version is a pre-release, list all current pre-releases
|
|
|
|
// otherwise filter out pre-releases
|
|
|
|
let isInPreRelease = versions[0].includes('-')
|
|
|
|
const filteredVersions: string[] = []
|
|
|
|
for (const v of versions) {
|
|
|
|
if (v.includes('-')) {
|
|
|
|
if (isInPreRelease) {
|
|
|
|
filteredVersions.push(v)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
filteredVersions.push(v)
|
|
|
|
isInPreRelease = false
|
|
|
|
}
|
|
|
|
if (filteredVersions.length >= 30 || v === '3.0.10') {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filteredVersions
|
2021-03-31 10:00:46 +08:00
|
|
|
}
|
2021-03-29 11:36:36 +08:00
|
|
|
</script>
|
|
|
|
|
2021-06-23 22:13:23 +08:00
|
|
|
<template>
|
|
|
|
<nav>
|
|
|
|
<h1>
|
2021-08-24 00:21:17 +08:00
|
|
|
<img alt="logo" src="/logo.svg" />
|
2021-06-23 22:13:23 +08:00
|
|
|
<span>Vue SFC Playground</span>
|
|
|
|
</h1>
|
|
|
|
<div class="links">
|
|
|
|
<div class="version" @click.stop>
|
|
|
|
<span class="active-version" @click="toggle">
|
|
|
|
Version: {{ activeVersion }}
|
|
|
|
</span>
|
|
|
|
<ul class="versions" :class="{ expanded }">
|
|
|
|
<li v-if="!publishedVersions"><a>loading versions...</a></li>
|
|
|
|
<li v-for="version of publishedVersions">
|
|
|
|
<a @click="setVueVersion(version)">v{{ version }}</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
2021-08-24 00:21:17 +08:00
|
|
|
<a @click="resetVueVersion">This Commit ({{ currentCommit }})</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
href="https://app.netlify.com/sites/vue-sfc-playground/deploys"
|
|
|
|
target="_blank"
|
|
|
|
>Commits History</a
|
|
|
|
>
|
2021-06-23 22:13:23 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2022-05-17 12:10:29 +08:00
|
|
|
<button
|
|
|
|
title="Toggle development production mode"
|
|
|
|
class="toggle-dev"
|
|
|
|
:class="{ dev }"
|
|
|
|
@click="$emit('toggle-dev')"
|
|
|
|
>
|
|
|
|
{{ dev ? 'DEV' : 'PROD' }}
|
|
|
|
</button>
|
2021-09-17 05:21:48 +08:00
|
|
|
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
|
2021-09-17 02:23:09 +08:00
|
|
|
<Sun class="light" />
|
|
|
|
<Moon class="dark" />
|
2021-08-24 00:21:17 +08:00
|
|
|
</button>
|
2021-09-17 05:21:48 +08:00
|
|
|
<button title="Copy sharable URL" class="share" @click="copyLink">
|
|
|
|
<Share />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
title="Download project files"
|
|
|
|
class="download"
|
|
|
|
@click="downloadProject(store)"
|
|
|
|
>
|
2021-09-17 02:23:09 +08:00
|
|
|
<Download />
|
2021-06-23 22:13:23 +08:00
|
|
|
</button>
|
2022-05-17 12:10:29 +08:00
|
|
|
<button title="View on GitHub" class="github">
|
2021-12-12 10:01:48 +08:00
|
|
|
<a
|
2022-05-17 12:10:29 +08:00
|
|
|
href="https://github.com/vuejs/core/tree/main/packages/sfc-playground"
|
|
|
|
target="_blank"
|
2021-12-12 10:01:48 +08:00
|
|
|
>
|
|
|
|
<GitHub />
|
|
|
|
</a>
|
|
|
|
</button>
|
2021-06-23 22:13:23 +08:00
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</template>
|
|
|
|
|
2021-03-28 13:35:45 +08:00
|
|
|
<style>
|
|
|
|
nav {
|
2021-09-07 12:29:18 +08:00
|
|
|
--bg: #fff;
|
|
|
|
--bg-light: #fff;
|
|
|
|
--border: #ddd;
|
|
|
|
|
|
|
|
color: var(--base);
|
2021-03-28 13:35:45 +08:00
|
|
|
height: var(--nav-height);
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 0 1em;
|
2021-09-07 12:29:18 +08:00
|
|
|
background-color: var(--bg);
|
2021-03-28 13:35:45 +08:00
|
|
|
box-shadow: 0 0 4px rgba(0, 0, 0, 0.33);
|
|
|
|
position: relative;
|
|
|
|
z-index: 999;
|
2021-03-29 14:07:04 +08:00
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
2021-03-28 13:35:45 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 12:29:18 +08:00
|
|
|
.dark nav {
|
|
|
|
--base: #ddd;
|
|
|
|
--bg: #1a1a1a;
|
|
|
|
--bg-light: #242424;
|
|
|
|
--border: #383838;
|
|
|
|
|
|
|
|
box-shadow: none;
|
|
|
|
border-bottom: 1px solid var(--border);
|
|
|
|
}
|
|
|
|
|
2021-03-28 13:35:45 +08:00
|
|
|
h1 {
|
|
|
|
margin: 0;
|
|
|
|
line-height: var(--nav-height);
|
|
|
|
font-weight: 500;
|
2021-03-29 14:07:04 +08:00
|
|
|
display: inline-block;
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
|
2021-03-29 22:17:33 +08:00
|
|
|
h1 img {
|
|
|
|
height: 24px;
|
|
|
|
vertical-align: middle;
|
|
|
|
margin-right: 10px;
|
|
|
|
position: relative;
|
|
|
|
top: -2px;
|
|
|
|
}
|
|
|
|
|
2021-09-17 02:23:09 +08:00
|
|
|
@media (max-width: 560px) {
|
|
|
|
h1 span {
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 21:24:14 +08:00
|
|
|
@media (max-width: 520px) {
|
2021-03-29 22:17:33 +08:00
|
|
|
h1 span {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-31 10:00:46 +08:00
|
|
|
.links {
|
|
|
|
display: flex;
|
2021-03-28 13:35:45 +08:00
|
|
|
}
|
2021-03-29 11:36:36 +08:00
|
|
|
|
2021-03-31 10:00:46 +08:00
|
|
|
.version {
|
|
|
|
display: inline-block;
|
|
|
|
margin-right: 12px;
|
2021-03-29 14:07:04 +08:00
|
|
|
position: relative;
|
2021-03-29 11:36:36 +08:00
|
|
|
}
|
|
|
|
|
2021-03-31 10:00:46 +08:00
|
|
|
.active-version {
|
|
|
|
cursor: pointer;
|
2021-03-29 14:07:04 +08:00
|
|
|
position: relative;
|
2021-03-31 10:00:46 +08:00
|
|
|
display: inline-block;
|
|
|
|
vertical-align: middle;
|
|
|
|
line-height: var(--nav-height);
|
|
|
|
padding-right: 15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.active-version:after {
|
|
|
|
content: '';
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
border-left: 4px solid transparent;
|
|
|
|
border-right: 4px solid transparent;
|
|
|
|
border-top: 6px solid #aaa;
|
|
|
|
position: absolute;
|
|
|
|
right: 0;
|
|
|
|
top: 22px;
|
|
|
|
}
|
|
|
|
|
2022-05-17 12:10:29 +08:00
|
|
|
.toggle-dev {
|
|
|
|
color: #f07178;
|
|
|
|
font-size: 12px;
|
|
|
|
line-height: var(--nav-height);
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle-dev.dev {
|
|
|
|
color: #c3e88d;
|
|
|
|
}
|
|
|
|
|
2021-09-17 02:23:09 +08:00
|
|
|
.toggle-dark svg {
|
|
|
|
width: 18px;
|
|
|
|
height: 18px;
|
|
|
|
fill: #666;
|
|
|
|
}
|
|
|
|
|
|
|
|
.toggle-dark .dark,
|
|
|
|
.dark .toggle-dark .light {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.dark .toggle-dark .dark {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
|
2021-03-31 10:00:46 +08:00
|
|
|
.version:hover .active-version:after {
|
|
|
|
border-top-color: var(--base);
|
2021-03-29 14:07:04 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 12:29:18 +08:00
|
|
|
.dark .version:hover .active-version:after {
|
|
|
|
border-top-color: #fff;
|
|
|
|
}
|
|
|
|
|
2021-03-31 10:00:46 +08:00
|
|
|
.versions {
|
|
|
|
display: none;
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
top: 40px;
|
2021-09-07 12:29:18 +08:00
|
|
|
background-color: var(--bg-light);
|
|
|
|
border: 1px solid var(--border);
|
2021-03-31 10:00:46 +08:00
|
|
|
border-radius: 4px;
|
|
|
|
list-style-type: none;
|
|
|
|
padding: 8px;
|
|
|
|
margin: 0;
|
|
|
|
width: 200px;
|
|
|
|
max-height: calc(100vh - 70px);
|
|
|
|
overflow: scroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
.versions a {
|
|
|
|
display: block;
|
|
|
|
padding: 6px 12px;
|
|
|
|
text-decoration: none;
|
|
|
|
cursor: pointer;
|
|
|
|
color: var(--base);
|
|
|
|
}
|
|
|
|
|
|
|
|
.versions a:hover {
|
2021-09-07 06:02:27 +08:00
|
|
|
color: #3ca877;
|
2021-03-31 10:00:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.versions.expanded {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.share,
|
2021-12-12 10:01:48 +08:00
|
|
|
.download,
|
|
|
|
.github {
|
2021-03-31 10:00:46 +08:00
|
|
|
margin: 0 2px;
|
2021-03-29 11:36:36 +08:00
|
|
|
}
|
2021-03-28 13:35:45 +08:00
|
|
|
</style>
|