Skip to content

Commit a6a16ee

Browse files
authored
feat: reset editor files (#314)
* chore: resolve conflicts & cleanup * chore: cleanup
1 parent 0f17cc3 commit a6a16ee

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/auto-imports.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// @ts-nocheck
44
// noinspection JSUnusedGlobalSymbols
55
// Generated by unplugin-auto-import
6+
// biome-ignore lint: disable
67
export {}
78
declare global {
89
const EffectScope: typeof import('vue')['EffectScope']
@@ -25,6 +26,7 @@ declare global {
2526
const createGlobalState: typeof import('@vueuse/core')['createGlobalState']
2627
const createInjectionState: typeof import('@vueuse/core')['createInjectionState']
2728
const createReactiveFn: typeof import('@vueuse/core')['createReactiveFn']
29+
const createRef: typeof import('@vueuse/core')['createRef']
2830
const createReusableTemplate: typeof import('@vueuse/core')['createReusableTemplate']
2931
const createSharedComposable: typeof import('@vueuse/core')['createSharedComposable']
3032
const createTemplatePromise: typeof import('@vueuse/core')['createTemplatePromise']
@@ -296,6 +298,9 @@ declare global {
296298
// for type re-export
297299
declare global {
298300
// @ts-ignore
299-
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
301+
export type { Component, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
300302
import('vue')
303+
// @ts-ignore
304+
export type { Initial, VersionKey, Versions, UserOptions, SerializeState, Store } from './composables/store'
305+
import('./composables/store')
301306
}

src/components.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// @ts-nocheck
33
// Generated by unplugin-vue-components
44
// Read more: https://github.com/vuejs/core/pull/3399
5+
// biome-ignore lint: disable
56
export {}
67

78
/* prettier-ignore */
89
declare module 'vue' {
910
export interface GlobalComponents {
11+
ElButton: typeof import('element-plus/es')['ElButton']
1012
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
1113
ElForm: typeof import('element-plus/es')['ElForm']
1214
ElFormItem: typeof import('element-plus/es')['ElFormItem']
@@ -19,7 +21,7 @@ declare module 'vue' {
1921
Header: typeof import('./components/Header.vue')['default']
2022
Settings: typeof import('./components/Settings.vue')['default']
2123
}
22-
export interface ComponentCustomProperties {
24+
export interface GlobalDirectives {
2325
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
2426
}
2527
}

src/components/Header.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ const replVersion = import.meta.env.REPL_VERSION
1313
1414
const emit = defineEmits<{
1515
(e: 'refresh'): void
16+
(e: 'reset'): void
1617
}>()
1718
const nightly = ref(false)
19+
const showReset = ref(false)
1820
const dark = useDark()
1921
const toggleDark = useToggle(dark)
2022
@@ -65,6 +67,10 @@ async function copyLink() {
6567
function refreshView() {
6668
emit('refresh')
6769
}
70+
function resetFiles() {
71+
showReset.value = false
72+
store.resetFiles()
73+
}
6874
</script>
6975

7076
<template>
@@ -149,6 +155,26 @@ function refreshView() {
149155
</div>
150156

151157
<div flex="~ gap-4" text-lg>
158+
<el-popover
159+
v-model:visible="showReset"
160+
popper-class="flex flex-col gap-1"
161+
trigger="click"
162+
width="200px"
163+
>
164+
<div flex justify-center>Want to reset the editor ?</div>
165+
<el-button
166+
flex
167+
self-end
168+
size="small"
169+
plain
170+
@click="resetFiles"
171+
>
172+
Yes
173+
</el-button>
174+
<template #reference>
175+
<button i-ri-delete-bin-line hover:color-primary />
176+
</template>
177+
</el-popover>
152178
<button
153179
i-ri-refresh-line
154180
title="Refresh sandbox"

src/composables/store.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ export const useStore = (initial: Initial) => {
249249
}
250250
}
251251

252+
const resetFiles = () => {
253+
const { files, addFile } = store
254+
255+
const isRandomFile = (filename: string) =>
256+
![MAIN_FILE, TSCONFIG, IMPORT_MAP, ELEMENT_PLUS_FILE].includes(
257+
filename,
258+
)
259+
for (const filename in files)
260+
if (isRandomFile(filename)) delete files[filename]
261+
262+
const appFile = new File(APP_FILE, welcomeCode, false)
263+
addFile(appFile)
264+
}
265+
252266
const utils = {
253267
versions,
254268
pr,
@@ -257,6 +271,7 @@ export const useStore = (initial: Initial) => {
257271
serialize,
258272
init,
259273
vuePr,
274+
resetFiles,
260275
}
261276
Object.assign(store, utils)
262277

0 commit comments

Comments
 (0)