Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow starting on a specific view #15

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
types: improve external compatibility for output modes
  • Loading branch information
posva committed Dec 17, 2021
commit 8354253a46261dccd943c30e982ce0667c76ae15
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ import '@vue/repl/style.css'
import { watchEffect } from 'vue'
import { Repl, ReplStore } from '@vue/repl'

// retrieve some configuration options from the URL
const query = new URLSearchParams(location.search)

const store = new ReplStore({
// initialize repl with previously serialized state
serializedState: location.hash.slice(1),

// start on the output pane in mobile devices, defaults to false
showOutput: true,
showOutput: query.has('showOutput'),
// start on the JS output tab, defaults to "preview"
outputMode: 'js',
outputMode: (query.get('outputMode') || 'preview')

// specify the default URL to import Vue runtime from in the sandbox
// default is the CDN link from unpkg.com with version matching Vue's version
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as Repl } from './Repl.vue'
export { ReplStore, File } from './store'
export type { SFCOptions, StoreState } from './store'
export type { OutputModes } from './output/types'
6 changes: 5 additions & 1 deletion src/output/Output.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const modes = computed(() =>
: (['preview'] as const)
)

const mode = ref<OutputModes>(store.initialOutputMode)
const mode = ref<OutputModes>(
(modes.value as readonly string[]).includes(store.initialOutputMode)
? store.initialOutputMode as OutputModes
: 'preview'
)
</script>

<template>
Expand Down
5 changes: 3 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ReplStore {
compiler = defaultCompiler
options?: SFCOptions
initialShowOutput: boolean
initialOutputMode: OutputModes
initialOutputMode: OutputModes | string

private defaultVueRuntimeURL: string
private pendingCompiler: Promise<any> | null = null
Expand All @@ -71,7 +71,8 @@ export class ReplStore {
}: {
serializedState?: string
showOutput?: boolean
outputMode?: OutputModes
// loose type to allow getting from the URL without inducing a typing error
outputMode?: OutputModes | string
defaultVueRuntimeURL?: string
} = {}) {
let files: StoreState['files'] = {}
Expand Down