Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ defineExpose({ reload })
margin: 0;
overflow: hidden;
font-size: 13px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: var(--bg-soft);
}

Expand Down
2 changes: 1 addition & 1 deletion src/import-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function getVersions(version: string): number[] {
return version.split('.').map((v) => parseInt(v, 10))
}

export function isVaporSupported(version: string): boolean{
export function isVaporSupported(version: string): boolean {
const [major, minor] = getVersions(version)
// vapor mode is supported in v3.6+
return major > 3 || (major === 3 && minor >= 6)
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export { default as Repl, type Props as ReplProps } from './Repl.vue'
export { default as Preview } from './output/Preview.vue'
export { default as Sandbox, type SandboxProps } from './output/Sandbox.vue'
export type { OutputModes } from './types'
export { utoa, atou } from './utils'
export * from './core'
4 changes: 3 additions & 1 deletion src/output/Output.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ watchEffect(() => {
})

const showSourceMap = computed(() => {
return props.showOpenSourceMap && (mode.value === 'js' || mode.value === 'ssr')
return (
props.showOpenSourceMap && (mode.value === 'js' || mode.value === 'ssr')
)
})

function openSourceMap() {
Expand Down
2 changes: 1 addition & 1 deletion src/output/Sandbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async function updatePreview() {
}

const vaporSupported = isVaporSupported(
store.value.vueVersion || store.value.compiler?.version
store.value.vueVersion || store.value.compiler?.version,
)

try {
Expand Down
5 changes: 3 additions & 2 deletions src/output/srcdoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
color-scheme: dark;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
</style>
<!-- PREVIEW-OPTIONS-HEAD-HTML -->
Expand Down
3 changes: 1 addition & 2 deletions src/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ export function getSourceMap(
// same above
templateMap as Omit<RawSourceMap, 'version'> as TraceEncodedSourceMap,
)
const offset =
(trimAnalyzedBindings(scriptCode).match(/\r?\n/g)?.length ?? 0)
const offset = trimAnalyzedBindings(scriptCode).match(/\r?\n/g)?.length ?? 0
eachMapping(tracer, (m) => {
if (m.source == null) return
addMapping(gen, {
Expand Down
9 changes: 9 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export function useStore(
typescriptVersion = ref('latest'),
dependencyVersion = ref(Object.create(null)),
reloadLanguageTools = ref(),

customData = ref({}),
}: Partial<StoreState> = {},
serializedState?: string,
): ReplStore {
Expand Down Expand Up @@ -273,6 +275,9 @@ export function useStore(
if (typescriptVersion.value !== 'latest' || files._tsVersion) {
files._tsVersion = typescriptVersion.value
}
if (customData.value && Object.keys(customData.value).length) {
files.__metadata = JSON.stringify(customData.value)
}
return '#' + utoa(JSON.stringify(files))
}
const deserialize: ReplStore['deserialize'] = (
Expand All @@ -294,6 +299,8 @@ export function useStore(
vueVersion.value = saved[filename]
} else if (filename === '_tsVersion') {
typescriptVersion.value = saved[filename]
} else if (filename === '__metadata') {
customData.value = JSON.parse(saved[filename])
} else {
setFile(files.value, filename, saved[filename])
}
Expand Down Expand Up @@ -372,6 +379,7 @@ export function useStore(
compiler,
loading,
vueVersion,
customData,

locale,
typescriptVersion,
Expand Down Expand Up @@ -438,6 +446,7 @@ export type StoreState = ToRefs<{
compiler: typeof defaultCompiler
/* only apply for compiler-sfc */
vueVersion: string | null
customData: Record<string, any>

// volar-related
locale: string | undefined
Expand Down
12 changes: 10 additions & 2 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ export async function compileFile(
let clientScript: string
let bindings: BindingMetadata | undefined
try {
const res = await doCompileScript(store, descriptor, id, false, isTS, isJSX, isCE)
const res = await doCompileScript(
store,
descriptor,
id,
false,
isTS,
isJSX,
isCE,
)
clientScript = res.code
bindings = res.bindings
clientScriptMap = res.map
Expand All @@ -159,7 +167,7 @@ export async function compileFile(
true,
isTS,
isJSX,
isCE
isCE,
)
ssrScript = ssrScriptResult.code
ssrCode += ssrScript
Expand Down