From d0b513eb463f580e29378e43d112ff6859aa366e Mon Sep 17 00:00:00 2001 From: Hongkun Date: Tue, 10 Sep 2024 19:15:29 +0800 Subject: [PATCH] chore(sfc-playground): editor can modify whether auto-save is enabled (#11428) --- packages-private/sfc-playground/package.json | 2 +- packages-private/sfc-playground/src/App.vue | 14 ++++++++++++++ .../sfc-playground/src/Header.vue | 19 ++++++++++++++++--- pnpm-lock.yaml | 10 +++++----- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/packages-private/sfc-playground/package.json b/packages-private/sfc-playground/package.json index b43247e9cb9..2d1db99fab2 100644 --- a/packages-private/sfc-playground/package.json +++ b/packages-private/sfc-playground/package.json @@ -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:*" diff --git a/packages-private/sfc-playground/src/App.vue b/packages-private/sfc-playground/src/App.vue index 7cbe573f6e2..9ae0ecd9236 100644 --- a/packages-private/sfc-playground/src/App.vue +++ b/packages-private/sfc-playground/src/App.vue @@ -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` @@ -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() } @@ -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" /> { @keydown.ctrl.s.prevent @keydown.meta.s.prevent :ssr="useSSRMode" + :autoSave="autoSave" :store="store" :showCompileOutput="true" :autoResize="true" diff --git a/packages-private/sfc-playground/src/Header.vue b/packages-private/sfc-playground/src/Header.vue index 922a2b111ac..2778724b0ab 100644 --- a/packages-private/sfc-playground/src/Header.vue +++ b/packages-private/sfc-playground/src/Header.vue @@ -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', ]) @@ -107,6 +109,14 @@ function toggleDark() { > {{ ssr ? 'SSR ON' : 'SSR OFF' }} +