@@ -5,19 +5,7 @@ import { computed, inject, ref, VNode, Ref } from 'vue'
55const store = inject (' store' ) as Store
66
77const pending = ref (false )
8- const newFileCount = ref (0 )
9- const customizedFilename = ref (' ' )
10- const pendingFilename = computed ({
11- get(): string {
12- if (customizedFilename .value ) {
13- return customizedFilename .value
14- }
15- return newFileCount .value > 0 ? ` Comp${newFileCount .value }.vue ` : ' Comp.vue'
16- },
17- set(name : string ) {
18- customizedFilename .value = name
19- }
20- })
8+ const pendingFilename = ref (' Comp.vue' )
219const importMapFile = ' import-map.json'
2210const showImportMap = inject (' import-map' ) as Ref <boolean >
2311const files = computed (() =>
@@ -27,6 +15,24 @@ const files = computed(() =>
2715)
2816
2917function startAddFile() {
18+ let i = 0
19+ let name = ` Comp.vue `
20+
21+ while (true ) {
22+ let hasConflict = false
23+ for (const file in store .state .files ) {
24+ if (file === name ) {
25+ hasConflict = true
26+ name = ` Comp${++ i }.vue `
27+ break
28+ }
29+ }
30+ if (! hasConflict ) {
31+ break
32+ }
33+ }
34+
35+ pendingFilename .value = name
3036 pending .value = true
3137}
3238
@@ -57,17 +63,14 @@ function doneAddFile() {
5763 store .state .errors = []
5864 cancelAddFile ()
5965 store .addFile (filename )
60- customizedFilename .value = ' '
61- if (filename === pendingFilename .value ) {
62- newFileCount .value ++
63- }
6466}
6567
6668const fileSel = ref (null )
6769function horizontalScroll(e : WheelEvent ) {
6870 e .preventDefault ()
6971 const el = fileSel .value ! as HTMLElement
70- const direction = Math .abs (e .deltaX ) >= Math .abs (e .deltaY ) ? e .deltaX : e .deltaY
72+ const direction =
73+ Math .abs (e .deltaX ) >= Math .abs (e .deltaY ) ? e .deltaX : e .deltaY
7174 const distance = 30 * (direction > 0 ? 1 : - 1 )
7275 el .scrollTo ({
7376 left: el .scrollLeft + distance
@@ -76,7 +79,12 @@ function horizontalScroll(e: WheelEvent) {
7679 </script >
7780
7881<template >
79- <div class =" file-selector" :class =" { 'has-import-map': showImportMap }" @wheel =" horizontalScroll" ref =" fileSel" >
82+ <div
83+ class =" file-selector"
84+ :class =" { 'has-import-map': showImportMap }"
85+ @wheel =" horizontalScroll"
86+ ref =" fileSel"
87+ >
8088 <div
8189 v-for =" (file, i) in files"
8290 class =" file"
0 commit comments