@@ -5,19 +5,7 @@ import { computed, inject, ref, VNode, Ref } from 'vue'
5
5
const store = inject (' store' ) as Store
6
6
7
7
const 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' )
21
9
const importMapFile = ' import-map.json'
22
10
const showImportMap = inject (' import-map' ) as Ref <boolean >
23
11
const files = computed (() =>
@@ -27,6 +15,24 @@ const files = computed(() =>
27
15
)
28
16
29
17
function 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
30
36
pending .value = true
31
37
}
32
38
@@ -57,17 +63,14 @@ function doneAddFile() {
57
63
store .state .errors = []
58
64
cancelAddFile ()
59
65
store .addFile (filename )
60
- customizedFilename .value = ' '
61
- if (filename === pendingFilename .value ) {
62
- newFileCount .value ++
63
- }
64
66
}
65
67
66
68
const fileSel = ref (null )
67
69
function horizontalScroll(e : WheelEvent ) {
68
70
e .preventDefault ()
69
71
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
71
74
const distance = 30 * (direction > 0 ? 1 : - 1 )
72
75
el .scrollTo ({
73
76
left: el .scrollLeft + distance
@@ -76,7 +79,12 @@ function horizontalScroll(e: WheelEvent) {
76
79
</script >
77
80
78
81
<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
+ >
80
88
<div
81
89
v-for =" (file, i) in files"
82
90
class =" file"
0 commit comments