1
1
<script setup lang="ts">
2
- import {
3
- type Store ,
4
- importMapFile ,
5
- stripSrcPrefix ,
6
- tsconfigFile ,
7
- } from ' ../store'
2
+ import { injectKeyStore } from ' ../../src/types'
3
+ import { importMapFile , stripSrcPrefix , tsconfigFile } from ' ../store'
8
4
import { type Ref , type VNode , computed , inject , ref } from ' vue'
9
5
10
- const store = inject (' store ' ) as Store
6
+ const store = inject (injectKeyStore ) !
11
7
12
8
/**
13
9
* When `true`: indicates adding a new file
@@ -23,7 +19,7 @@ const pendingFilename = ref('Comp.vue')
23
19
const showTsConfig = inject <Ref <boolean >>(' tsconfig' )
24
20
const showImportMap = inject <Ref <boolean >>(' import-map' )
25
21
const files = computed (() =>
26
- Object .entries (store .state . files )
22
+ Object .entries (store .files )
27
23
.filter (
28
24
([name , file ]) =>
29
25
name !== importMapFile && name !== tsconfigFile && ! file .hidden ,
@@ -37,7 +33,7 @@ function startAddFile() {
37
33
38
34
while (true ) {
39
35
let hasConflict = false
40
- for (const filename in store .state . files ) {
36
+ for (const filename in store .files ) {
41
37
if (stripSrcPrefix (filename ) === name ) {
42
38
hasConflict = true
43
39
name = ` Comp${++ i }.vue `
@@ -68,18 +64,18 @@ function doneNameFile() {
68
64
const oldFilename = pending .value === true ? ' ' : pending .value
69
65
70
66
if (! / \. (vue| js| ts| css| json)$ / .test (filename )) {
71
- store .state . errors = [
67
+ store .errors = [
72
68
` Playground only supports *.vue, *.js, *.ts, *.css, *.json files. ` ,
73
69
]
74
70
return
75
71
}
76
72
77
- if (filename !== oldFilename && filename in store .state . files ) {
78
- store .state . errors = [` File "${filename }" already exists. ` ]
73
+ if (filename !== oldFilename && filename in store .files ) {
74
+ store .errors = [` File "${filename }" already exists. ` ]
79
75
return
80
76
}
81
77
82
- store .state . errors = []
78
+ store .errors = []
83
79
cancelNameFile ()
84
80
85
81
if (filename === oldFilename ) {
@@ -122,7 +118,7 @@ function horizontalScroll(e: WheelEvent) {
122
118
<div
123
119
v-if =" pending !== file"
124
120
class =" file"
125
- :class =" { active: store.state. activeFile.filename === file }"
121
+ :class =" { active: store.activeFile.filename === file }"
126
122
@click =" store.setActive(file)"
127
123
@dblclick =" i > 0 && editFileName(file)"
128
124
>
@@ -154,17 +150,17 @@ function horizontalScroll(e: WheelEvent) {
154
150
155
151
<div class =" import-map-wrapper" >
156
152
<div
157
- v-if =" showTsConfig && store.state. files[tsconfigFile]"
153
+ v-if =" showTsConfig && store.files[tsconfigFile]"
158
154
class =" file"
159
- :class =" { active: store.state. activeFile.filename === tsconfigFile }"
155
+ :class =" { active: store.activeFile.filename === tsconfigFile }"
160
156
@click =" store.setActive(tsconfigFile)"
161
157
>
162
158
<span class =" label" >tsconfig.json</span >
163
159
</div >
164
160
<div
165
161
v-if =" showImportMap"
166
162
class =" file"
167
- :class =" { active: store.state. activeFile.filename === importMapFile }"
163
+ :class =" { active: store.activeFile.filename === importMapFile }"
168
164
@click =" store.setActive(importMapFile)"
169
165
>
170
166
<span class =" label" >Import Map</span >
0 commit comments