Skip to content

Commit fd6fce4

Browse files
feat(sfc-playground): add ability to disable automatic url generation
1 parent 5898629 commit fd6fce4

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/sfc-playground/src/App.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import Header from './Header.vue'
33
import { Repl, ReplStore } from '@vue/repl'
4-
import { watchEffect } from 'vue'
4+
import { watchEffect, ref } from 'vue'
55
66
const setVH = () => {
77
document.documentElement.style.setProperty('--vh', window.innerHeight + `px`)
@@ -23,12 +23,14 @@ const sfcOptions = {
2323
}
2424
}
2525
26+
const autoUrl = ref(true);
27+
2628
// persist state
27-
watchEffect(() => history.replaceState({}, '', store.serialize()))
29+
watchEffect(() => autoUrl.value && history.replaceState({}, '', store.serialize()))
2830
</script>
2931

3032
<template>
31-
<Header :store="store" />
33+
<Header :store="store" v-model:auto-url="autoUrl" />
3234
<Repl
3335
@keydown.ctrl.s.prevent
3436
@keydown.meta.s.prevent

packages/sfc-playground/src/Header.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
<script setup lang="ts">
22
import { downloadProject } from './download/download'
3-
import { ref, onMounted } from 'vue'
3+
import { ref, onMounted, defineEmits, computed } from 'vue'
44
import Sun from './icons/Sun.vue'
55
import Moon from './icons/Moon.vue'
66
import Share from './icons/Share.vue'
77
import Download from './icons/Download.vue'
88
import GitHub from './icons/GitHub.vue'
99
1010
// @ts-ignore
11-
const { store } = defineProps(['store'])
11+
const { store, autoUrl } = defineProps(['store', 'autoUrl'])
12+
const emit = defineEmits(['update:autoUrl']);
1213
1314
const currentCommit = __COMMIT__
1415
const activeVersion = ref(`@${currentCommit}`)
1516
const publishedVersions = ref<string[]>()
1617
const expanded = ref(false)
1718
19+
const autoUrlRef = computed({
20+
get: () => autoUrl,
21+
set: value => emit("update:autoUrl", value)
22+
});
23+
1824
async function toggle() {
1925
expanded.value = !expanded.value
2026
if (!publishedVersions.value) {
@@ -91,6 +97,10 @@ async function fetchVersions(): Promise<string[]> {
9197
<span>Vue SFC Playground</span>
9298
</h1>
9399
<div class="links">
100+
<div class="url-generation">
101+
<input type="checkbox" v-model="autoUrlRef" id="auto-url">
102+
<label for="auto-url">Auto URL</label>
103+
</div>
94104
<div class="version" @click.stop>
95105
<span class="active-version" @click="toggle">
96106
Version: {{ activeVersion }}
@@ -288,4 +298,15 @@ h1 img {
288298
.github {
289299
margin: 0 2px;
290300
}
301+
302+
.url-generation {
303+
display: flex;
304+
flex-direction: row;
305+
margin: 0 2px;
306+
align-items: center;
307+
gap: 2px;
308+
border-right: 2px solid var(--border);
309+
padding: 5px;
310+
user-select: none;
311+
}
291312
</style>

0 commit comments

Comments
 (0)