File tree Expand file tree Collapse file tree 7 files changed +35
-5
lines changed Expand file tree Collapse file tree 7 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -22,10 +22,19 @@ import '@vue/repl/style.css'
22
22
import { watchEffect } from 'vue'
23
23
import { Repl, ReplStore } from '@vue/repl'
24
24
25
+ // retrieve some configuration options from the URL
26
+ const query = new URLSearchParams(location.search)
27
+
25
28
const store = new ReplStore({
26
29
// initialize repl with previously serialized state
27
30
serializedState: location.hash.slice(1),
28
31
32
+ // starts on the output pane (mobile only) if the URL has a showOutput query
33
+ showOutput: query.has('showOutput'),
34
+ // starts on a different tab on the output pane if the URL has a outputMode query
35
+ // and default to the "preview" tab
36
+ outputMode: (query.get('outputMode') || 'preview')
37
+
29
38
// specify the default URL to import Vue runtime from in the sandbox
30
39
// default is the CDN link from unpkg.com with version matching Vue's version
31
40
// from peerDependency
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
- import { ref , reactive , computed } from ' vue'
2
+ import { ref , reactive , computed , inject } from ' vue'
3
+ import { Store } from ' ./store'
3
4
4
5
const props = defineProps <{ layout? : string }>()
5
6
const isVertical = computed (() => props .layout === ' vertical' )
6
7
7
8
const container = ref ()
8
9
9
10
// mobile only
10
- const showOutput = ref (false )
11
+ const store = inject (' store' ) as Store
12
+ const showOutput = ref (store .initialShowOutput )
11
13
12
14
const state = reactive ({
13
15
dragging: false ,
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ export { default as Repl } from './Repl.vue'
2
2
export { ReplStore , File } from './store'
3
3
export { compileFile } from './transform'
4
4
export type { Store , SFCOptions , StoreState } from './store'
5
+ export type { OutputModes } from './output/types'
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Preview from './Preview.vue'
3
3
import CodeMirror from ' ../codemirror/CodeMirror.vue'
4
4
import { Store } from ' ../store'
5
5
import { inject , ref , computed } from ' vue'
6
+ import type { OutputModes } from ' ./types'
6
7
7
8
const props = defineProps <{
8
9
showCompileOutput? : boolean
@@ -15,8 +16,11 @@ const modes = computed(() =>
15
16
: ([' preview' ] as const )
16
17
)
17
18
18
- type Modes = typeof modes .value [number ]
19
- const mode = ref <Modes >(' preview' )
19
+ const mode = ref <OutputModes >(
20
+ (modes .value as readonly string []).includes (store .initialOutputMode )
21
+ ? store .initialOutputMode as OutputModes
22
+ : ' preview'
23
+ )
20
24
</script >
21
25
22
26
<template >
Original file line number Diff line number Diff line change
1
+ export type OutputModes = 'preview' | 'js' | 'css' | 'ssr'
Original file line number Diff line number Diff line change 7
7
SFCAsyncStyleCompileOptions ,
8
8
SFCTemplateCompileOptions
9
9
} from 'vue/compiler-sfc'
10
+ import { OutputModes } from './output/types'
10
11
11
12
const defaultMainFile = 'App.vue'
12
13
@@ -66,15 +67,22 @@ export class ReplStore implements Store {
66
67
state : StoreState
67
68
compiler = defaultCompiler
68
69
options ?: SFCOptions
70
+ initialShowOutput : boolean
71
+ initialOutputMode : OutputModes | string
69
72
70
73
private defaultVueRuntimeURL : string
71
74
private pendingCompiler : Promise < any > | null = null
72
75
73
76
constructor ( {
74
77
serializedState = '' ,
75
- defaultVueRuntimeURL = `https://unpkg.com/@vue/runtime-dom@${ version } /dist/runtime-dom.esm-browser.js`
78
+ defaultVueRuntimeURL = `https://unpkg.com/@vue/runtime-dom@${ version } /dist/runtime-dom.esm-browser.js` ,
79
+ showOutput = false ,
80
+ outputMode = 'preview'
76
81
} : {
77
82
serializedState ?: string
83
+ showOutput ?: boolean
84
+ // loose type to allow getting from the URL without inducing a typing error
85
+ outputMode ?: OutputModes | string
78
86
defaultVueRuntimeURL ?: string
79
87
} = { } ) {
80
88
let files : StoreState [ 'files' ] = { }
@@ -91,6 +99,8 @@ export class ReplStore implements Store {
91
99
}
92
100
93
101
this . defaultVueRuntimeURL = defaultVueRuntimeURL
102
+ this . initialShowOutput = showOutput
103
+ this . initialOutputMode = outputMode
94
104
95
105
let mainFile = defaultMainFile
96
106
if ( ! files [ mainFile ] ) {
Original file line number Diff line number Diff line change @@ -5,8 +5,11 @@ import { Repl, ReplStore } from '../src'
5
5
6
6
const App = {
7
7
setup ( ) {
8
+ const query = new URLSearchParams ( location . search )
8
9
const store = new ReplStore ( {
9
10
serializedState : location . hash . slice ( 1 ) ,
11
+ showOutput : query . has ( 'so' ) ,
12
+ outputMode : query . get ( 'om' ) || 'preview' ,
10
13
defaultVueRuntimeURL : import . meta. env . PROD
11
14
? undefined
12
15
: `${ location . origin } /src/vue-dev-proxy`
You can’t perform that action at this time.
0 commit comments