Skip to content

Commit

Permalink
chore(sfc-playground): editor can modify whether auto-save is enabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
phk422 authored Sep 10, 2024
1 parent f599321 commit d0b513e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages-private/sfc-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"vite": "catalog:"
},
"dependencies": {
"@vue/repl": "^4.3.1",
"@vue/repl": "^4.4.0",
"file-saver": "^2.0.5",
"jszip": "^3.10.1",
"vue": "workspace:*"
Expand Down
14 changes: 14 additions & 0 deletions packages-private/sfc-playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ setVH()
const useSSRMode = ref(false)
const AUTO_SAVE_STORAGE_KEY = 'vue-sfc-playground-auto-save'
const initAutoSave: boolean = JSON.parse(
localStorage.getItem(AUTO_SAVE_STORAGE_KEY) ?? 'true',
)
const autoSave = ref(initAutoSave)
const { productionMode, vueVersion, importMap } = useVueImportMap({
runtimeDev: import.meta.env.PROD
? `${location.origin}/vue.runtime.esm-browser.js`
Expand Down Expand Up @@ -89,6 +95,11 @@ function toggleSSR() {
useSSRMode.value = !useSSRMode.value
}
function toggleAutoSave() {
autoSave.value = !autoSave.value
localStorage.setItem(AUTO_SAVE_STORAGE_KEY, String(autoSave.value))
}
function reloadPage() {
replRef.value?.reload()
}
Expand All @@ -111,9 +122,11 @@ onMounted(() => {
:store="store"
:prod="productionMode"
:ssr="useSSRMode"
:autoSave="autoSave"
@toggle-theme="toggleTheme"
@toggle-prod="toggleProdMode"
@toggle-ssr="toggleSSR"
@toggle-autosave="toggleAutoSave"
@reload-page="reloadPage"
/>
<Repl
Expand All @@ -123,6 +136,7 @@ onMounted(() => {
@keydown.ctrl.s.prevent
@keydown.meta.s.prevent
:ssr="useSSRMode"
:autoSave="autoSave"
:store="store"
:showCompileOutput="true"
:autoResize="true"
Expand Down
19 changes: 16 additions & 3 deletions packages-private/sfc-playground/src/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ const props = defineProps<{
store: ReplStore
prod: boolean
ssr: boolean
autoSave: boolean
}>()
const emit = defineEmits([
'toggle-theme',
'toggle-ssr',
'toggle-prod',
'toggle-autosave',
'reload-page',
])
Expand Down Expand Up @@ -107,6 +109,14 @@ function toggleDark() {
>
<span>{{ ssr ? 'SSR ON' : 'SSR OFF' }}</span>
</button>
<button
title="Toggle editor auto save mode"
class="toggle-autosave"
:class="{ enabled: autoSave }"
@click="$emit('toggle-autosave')"
>
<span>{{ autoSave ? 'AutoSave ON' : 'AutoSave OFF' }}</span>
</button>
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
<Sun class="light" />
<Moon class="dark" />
Expand Down Expand Up @@ -199,7 +209,8 @@ h1 img {
}
.toggle-prod span,
.toggle-ssr span {
.toggle-ssr span,
.toggle-autosave span {
font-size: 12px;
border-radius: 4px;
padding: 4px 6px;
Expand All @@ -214,11 +225,13 @@ h1 img {
background: var(--purple);
}
.toggle-ssr span {
.toggle-ssr span,
.toggle-autosave span {
background-color: var(--btn-bg);
}
.toggle-ssr.enabled span {
.toggle-ssr.enabled span,
.toggle-autosave.enabled span {
color: #fff;
background-color: var(--green);
}
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d0b513e

Please sign in to comment.