-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: useStore & useVueImportMap composable (#207)
- Loading branch information
Showing
15 changed files
with
554 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { computed, version as currentVersion, ref } from 'vue' | ||
|
||
export function useVueImportMap( | ||
defaults: { | ||
runtimeDev?: string | (() => string) | ||
runtimeProd?: string | (() => string) | ||
serverRenderer?: string | (() => string) | ||
} = {}, | ||
) { | ||
function normalizeDefaults(defaults?: string | (() => string)) { | ||
if (!defaults) return | ||
return typeof defaults === 'string' ? defaults : defaults() | ||
} | ||
|
||
const productionMode = ref(false) | ||
const vueVersion = ref<string | undefined>() | ||
const importMap = computed<ImportMap>(() => { | ||
const vue = | ||
(!vueVersion.value && | ||
normalizeDefaults( | ||
productionMode.value ? defaults.runtimeProd : defaults.runtimeDev, | ||
)) || | ||
`https://cdn.jsdelivr.net/npm/@vue/runtime-dom@${ | ||
vueVersion.value || currentVersion | ||
}/dist/runtime-dom.esm-browser${productionMode.value ? `.prod` : ``}.js` | ||
|
||
const serverRenderer = | ||
(!vueVersion.value && normalizeDefaults(defaults.serverRenderer)) || | ||
`https://cdn.jsdelivr.net/npm/@vue/server-renderer@${ | ||
vueVersion.value || currentVersion | ||
}/dist/server-renderer.esm-browser.js` | ||
return { | ||
imports: { | ||
vue, | ||
'vue/server-renderer': serverRenderer, | ||
}, | ||
} | ||
}) | ||
|
||
return { | ||
productionMode, | ||
importMap, | ||
vueVersion, | ||
defaultVersion: currentVersion, | ||
} | ||
} | ||
|
||
export interface ImportMap { | ||
imports?: Record<string, string | undefined> | ||
scopes?: Record<string, Record<string, string>> | ||
} | ||
|
||
export function mergeImportMap(a: ImportMap, b: ImportMap): ImportMap { | ||
return { | ||
imports: { ...a.imports, ...b.imports }, | ||
scopes: { ...a.scopes, ...b.scopes }, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
export { default as Repl } from './Repl.vue' | ||
export { default as Preview } from './output/Preview.vue' | ||
export { ReplStore, File } from './store' | ||
export { | ||
useStore, | ||
File, | ||
type SFCOptions, | ||
type StoreState, | ||
type Store, | ||
type ReplStore, | ||
} from './store' | ||
export { useVueImportMap, mergeImportMap, type ImportMap } from './import-map' | ||
export { compileFile } from './transform' | ||
export type { Props as ReplProps } from './Repl.vue' | ||
export type { Store, StoreOptions, SFCOptions, StoreState } from './store' | ||
export type { OutputModes } from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.