From 35b6f1a38611e31b9adbe7540d789be144e33bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Thu, 20 Jan 2022 18:25:36 +0800 Subject: [PATCH] feat: add hidden file (#17) --- src/editor/FileSelector.vue | 4 +++- src/store.ts | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/editor/FileSelector.vue b/src/editor/FileSelector.vue index a10b2260..fcb8c94d 100644 --- a/src/editor/FileSelector.vue +++ b/src/editor/FileSelector.vue @@ -9,7 +9,9 @@ const pendingFilename = ref('Comp.vue') const importMapFile = 'import-map.json' const showImportMap = inject('import-map') as Ref const files = computed(() => - Object.keys(store.state.files).filter((f) => f !== importMapFile) + Object.entries(store.state.files) + .filter(([name, file]) => name !== importMapFile && !file.hidden) + .map(([name]) => name) ) function startAddFile() { diff --git a/src/store.ts b/src/store.ts index 9e1e6874..70e2c61f 100644 --- a/src/store.ts +++ b/src/store.ts @@ -27,15 +27,17 @@ const msg = ref('Hello World!') export class File { filename: string code: string + hidden: boolean compiled = { js: '', css: '', ssr: '' } - constructor(filename: string, code = '') { + constructor(filename: string, code = '', hidden = false) { this.filename = filename this.code = code + this.hidden = hidden } } @@ -129,9 +131,15 @@ export class ReplStore implements Store { this.state.activeFile = this.state.files[filename] } - addFile(filename: string) { - this.state.files[filename] = new File(filename) - this.setActive(filename) + addFile(filename: string): void + addFile(file: File): void + addFile(fileOrFilename: string | File): void { + const file = + typeof fileOrFilename === 'string' + ? new File(fileOrFilename) + : fileOrFilename + this.state.files[file.filename] = file + if (!file.hidden) this.setActive(file.filename) } deleteFile(filename: string) {