File tree Expand file tree Collapse file tree 4 files changed +59
-5
lines changed Expand file tree Collapse file tree 4 files changed +59
-5
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,11 @@ const store = inject('store') as Store
7
7
const pending = ref (false )
8
8
const pendingFilename = ref (' Comp.vue' )
9
9
const importMapFile = ' import-map.json'
10
+ const linksFile = ' links.json'
10
11
const showImportMap = inject (' import-map' ) as Ref <boolean >
11
12
const files = computed (() =>
12
13
Object .entries (store .state .files )
13
- .filter (([name , file ]) => name !== importMapFile && ! file .hidden )
14
+ .filter (([name , file ]) => ! [ importMapFile , linksFile ]. includes ( name ) && ! file .hidden )
14
15
.map (([name ]) => name )
15
16
)
16
17
@@ -120,6 +121,9 @@ const activeFile = computed({
120
121
<v-tab v-if =" showImportMap" class =" file import-map" size =" small" :value =" importMapFile" >
121
122
Import Map
122
123
</v-tab >
124
+ <v-tab class =" file" size =" small" :value =" linksFile" >
125
+ Links
126
+ </v-tab >
123
127
</v-tabs >
124
128
</template >
125
129
Original file line number Diff line number Diff line change @@ -48,6 +48,17 @@ watch(
48
48
}
49
49
)
50
50
51
+ watch (
52
+ () => store .state .files [' links.json' ].code ,
53
+ () => {
54
+ try {
55
+ createSandbox ()
56
+ } catch (e ) {
57
+ store .state .errors = [e as Error ]
58
+ }
59
+ }
60
+ )
61
+
51
62
// reset sandbox when version changes
52
63
watch (() => store .state .resetFlip , createSandbox )
53
64
@@ -85,10 +96,23 @@ function createSandbox() {
85
96
if (! importMap .imports .vue ) {
86
97
importMap .imports .vue = store .state .vueRuntimeURL
87
98
}
88
- const sandboxSrc = srcdoc .replace (
89
- / <!--IMPORT_MAP-->/ ,
90
- JSON .stringify (importMap )
91
- )
99
+
100
+ const links = store .getLinks ()
101
+
102
+ if (! links .css ) {
103
+ links .css = []
104
+ }
105
+
106
+ const sandboxSrc = srcdoc
107
+ .replace (
108
+ / <!--IMPORT_MAP-->/ ,
109
+ JSON .stringify (importMap )
110
+ )
111
+ .replace (
112
+ / <!--CSS-->/ ,
113
+ links .css .map ((link : string ) => ` <link rel="stylesheet" type="text/css" href="${link }" /> ` ).join (' \n ' )
114
+ )
115
+
92
116
sandbox .srcdoc = sandboxSrc
93
117
container .value .appendChild (sandbox )
94
118
Original file line number Diff line number Diff line change 252
252
<!-- ES Module Shims: Import maps polyfill for modules browsers without import maps support (all except Chrome 89+) -->
253
253
< script async src ="
https://unpkg.com/[email protected] /dist/es-module-shims.wasm.js "
> </ script >
254
254
< script type ="importmap "> <!--IMPORT_MAP--></ script >
255
+ <!--CSS-->
255
256
</ head >
256
257
< body > </ body >
257
258
</ html >
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ export interface Store {
70
70
getImportMap : ( ) => any
71
71
initialShowOutput : boolean
72
72
initialOutputMode : OutputModes
73
+ getLinks : ( ) => any
73
74
}
74
75
75
76
export interface StoreOptions {
@@ -133,6 +134,7 @@ export class ReplStore implements Store {
133
134
} )
134
135
135
136
this . initImportMap ( )
137
+ this . initLinks ( )
136
138
}
137
139
138
140
// don't start compiling until the options are set
@@ -193,6 +195,7 @@ export class ReplStore implements Store {
193
195
this . state . mainFile = mainFile
194
196
this . state . files = files
195
197
this . initImportMap ( )
198
+ this . initLinks ( )
196
199
this . setActive ( mainFile )
197
200
this . forceSandboxReset ( )
198
201
}
@@ -231,6 +234,18 @@ export class ReplStore implements Store {
231
234
}
232
235
}
233
236
237
+ private initLinks ( ) {
238
+ const links = this . state . files [ 'links.json' ]
239
+ if ( ! links ) {
240
+ this . state . files [ 'links.json' ] = new File (
241
+ 'links.json' ,
242
+ JSON . stringify ( {
243
+ css : [ ]
244
+ } , null , 2 )
245
+ )
246
+ }
247
+ }
248
+
234
249
getImportMap ( ) {
235
250
try {
236
251
return JSON . parse ( this . state . files [ 'import-map.json' ] . code )
@@ -281,4 +296,14 @@ export class ReplStore implements Store {
281
296
this . forceSandboxReset ( )
282
297
console . info ( `[@vue/repl] Now using default Vue version` )
283
298
}
299
+
300
+ getLinks ( ) {
301
+ try {
302
+ return JSON . parse ( this . state . files [ 'links.json' ] . code )
303
+ } catch ( e ) {
304
+ this . state . errors = [
305
+ `Syntax error in links.json: ${ ( e as Error ) . message } `
306
+ ]
307
+ }
308
+ }
284
309
}
You can’t perform that action at this time.
0 commit comments