Skip to content
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
7 changes: 4 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ const handleKeydown = (evt: KeyboardEvent) => {
}

// persist state
watchEffect(() =>
watchEffect(() => {
store.typescriptVersion
history.replaceState(
{},
'',
`${location.origin}${location.pathname}#${store.serialize()}`,
),
)
)
})

const refreshPreview = () => {
replRef.value?.reload()
Expand Down
28 changes: 18 additions & 10 deletions src/composables/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export type Versions = Record<VersionKey, string>
export interface UserOptions {
styleSource?: string
showHidden?: boolean
vueVersion?: string
tsVersion?: string
elVersion?: string
}
export type SerializeState = Record<string, string> & {
_o?: UserOptions
Expand All @@ -50,15 +53,17 @@ export const useStore = (initial: Initial) => {
const prUrl = `https://preview-${pr}-element-plus.surge.sh/bundle/dist`

const versions = reactive<Versions>({
vue: 'latest',
elementPlus: pr ? 'preview' : 'latest',
typescript: 'latest',
vue: saved?._o?.vueVersion ?? 'latest',
elementPlus: pr
? 'preview'
: saved?._o?.elVersion ?? 'latest',
typescript: saved?._o?.tsVersion ?? 'latest',
})
const userOptions: UserOptions = pr
? {
showHidden: true,
styleSource: `${prUrl}/index.css`,
}
showHidden: true,
styleSource: `${prUrl}/index.css`,
}
: {}

const hideFile = !IS_DEV && !userOptions.showHidden
Expand Down Expand Up @@ -130,10 +135,10 @@ export const useStore = (initial: Initial) => {
const style = styleSource
? styleSource.replace('#VERSION#', version)
: genCdnLink(
nightly.value ? '@element-plus/nightly' : 'element-plus',
version,
'/dist/index.css',
)
nightly.value ? '@element-plus/nightly' : 'element-plus',
version,
'/dist/index.css',
)
const darkStyle = style.replace(
'/dist/index.css',
'/theme-chalk/dark/css-vars.css',
Expand Down Expand Up @@ -210,13 +215,16 @@ export const useStore = (initial: Initial) => {
async function setVersion(key: VersionKey, version: string) {
switch (key) {
case 'vue':
userOptions.vueVersion = version
await setVueVersion(version)
break
case 'elementPlus':
versions.elementPlus = version
userOptions.elVersion = version
break
case 'typescript':
store.typescriptVersion = version
userOptions.tsVersion = version
break
}
}
Expand Down