-
-
Notifications
You must be signed in to change notification settings - Fork 8k
/
Header.vue
350 lines (309 loc) 路 7.08 KB
/
Header.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<script setup lang="ts">
import { downloadProject } from './download/download'
import { ref, onMounted } from 'vue'
import Sun from './icons/Sun.vue'
import Moon from './icons/Moon.vue'
import Share from './icons/Share.vue'
import Download from './icons/Download.vue'
import GitHub from './icons/GitHub.vue'
// @ts-ignore
const props = defineProps(['store', 'dev', 'ssr'])
const { store } = props
const currentCommit = __COMMIT__
const activeVersion = ref(`@${currentCommit}`)
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...`
await store.setVueVersion(v)
activeVersion.value = `v${v}`
expanded.value = false
}
function resetVueVersion() {
store.resetVueVersion()
activeVersion.value = `@${currentCommit}`
expanded.value = false
}
async function copyLink() {
await navigator.clipboard.writeText(location.href)
alert('Sharable URL has been copied to clipboard.')
}
function toggleDark() {
const cls = document.documentElement.classList
cls.toggle('dark')
localStorage.setItem(
'vue-sfc-playground-prefer-dark',
String(cls.contains('dark'))
)
}
onMounted(async () => {
window.addEventListener('click', () => {
expanded.value = false
})
window.addEventListener('blur', () => {
if (document.activeElement?.tagName === 'IFRAME') {
expanded.value = false
}
});
})
async function fetchVersions(): Promise<string[]> {
const res = await fetch(
`https://api.github.com/repos/vuejs/core/releases?per_page=100`
)
const releases: any[] = await res.json()
const versions = releases.map(r =>
/^v/.test(r.tag_name) ? r.tag_name.slice(1) : r.tag_name
)
// 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
}
</script>
<template>
<nav>
<h1>
<img alt="logo" src="/logo.svg" />
<span>Vue SFC Playground</span>
</h1>
<div class="links">
<div class="version" @click.stop>
<span class="active-version" @click="toggle">
Version
<span class="number">{{ activeVersion }}</span>
</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>
<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
>
</li>
</ul>
</div>
<button
title="Toggle development production mode"
class="toggle-dev"
:class="{ dev }"
@click="$emit('toggle-dev')"
>
<span>{{ dev ? 'DEV' : 'PROD' }}</span>
</button>
<button
title="Toggle server rendering mode"
class="toggle-ssr"
:class="{ enabled: ssr }"
@click="$emit('toggle-ssr')"
>
<span>{{ ssr ? 'SSR ON' : 'SSR OFF' }}</span>
</button>
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
<Sun class="light" />
<Moon class="dark" />
</button>
<button title="Copy sharable URL" class="share" @click="copyLink">
<Share />
</button>
<button
title="Download project files"
class="download"
@click="downloadProject(store)"
>
<Download />
</button>
<button title="View on GitHub" class="github">
<a
href="https://github.com/vuejs/core/tree/main/packages/sfc-playground"
target="_blank"
>
<GitHub />
</a>
</button>
</div>
</nav>
</template>
<style>
nav {
--bg: #fff;
--bg-light: #fff;
--border: #ddd;
--btn: #666;
--highlight: #333;
--green: #3ca877;
--purple: #904cbc;
--btn-bg: #eee;
color: var(--base);
height: var(--nav-height);
box-sizing: border-box;
padding: 0 1em;
background-color: var(--bg);
box-shadow: 0 0 4px rgba(0, 0, 0, 0.33);
position: relative;
z-index: 999;
display: flex;
justify-content: space-between;
}
.dark nav {
--base: #ddd;
--bg: #1a1a1a;
--bg-light: #242424;
--border: #383838;
--highlight: #fff;
--btn-bg: #333;
box-shadow: none;
border-bottom: 1px solid var(--border);
}
h1 {
font-weight: 500;
display: inline-flex;
place-items: center;
}
h1 img {
height: 24px;
margin-right: 10px;
}
@media (max-width: 560px) {
h1 span {
font-size: 0.9em;
}
}
@media (max-width: 520px) {
h1 span {
display: none;
}
}
.links {
display: flex;
}
.version {
margin-right: 12px;
position: relative;
}
.active-version {
cursor: pointer;
position: relative;
display: inline-flex;
place-items: center;
}
.active-version .number {
color: var(--green);
margin-left: 4px;
}
.active-version::after {
content: '';
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 6px solid #aaa;
margin-left: 8px;
}
.toggle-dev span,
.toggle-ssr span {
font-size: 12px;
border-radius: 4px;
padding: 4px 6px;
}
.toggle-dev span {
background: var(--purple);
color: #fff;
}
.toggle-dev.dev span {
background: var(--green);
}
.toggle-ssr span {
background-color: var(--btn-bg);
}
.toggle-ssr.enabled span {
color: #fff;
background-color: var(--green);
}
.toggle-dark svg {
width: 18px;
height: 18px;
}
.toggle-dark .dark,
.dark .toggle-dark .light {
display: none;
}
.dark .toggle-dark .dark {
display: inline-block;
}
.links button,
.links button a {
color: var(--btn);
}
.links button:hover,
.links button:hover a {
color: var(--highlight);
}
.version:hover .active-version::after {
border-top-color: var(--btn);
}
.dark .version:hover .active-version::after {
border-top-color: var(--highlight);
}
.versions {
display: none;
position: absolute;
left: 0;
top: 40px;
background-color: var(--bg-light);
border: 1px solid var(--border);
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 {
color: var(--green);
}
.versions.expanded {
display: block;
}
.links > * {
display: flex;
align-items: center;
}
.links > * + * {
margin-left: 4px;
}
</style>