|
|
@ -5,12 +5,13 @@ import {
|
|
|
|
onMounted,
|
|
|
|
onMounted,
|
|
|
|
onUnmounted,
|
|
|
|
onUnmounted,
|
|
|
|
ref,
|
|
|
|
ref,
|
|
|
|
watchEffect
|
|
|
|
watchEffect,
|
|
|
|
|
|
|
|
watch
|
|
|
|
} from 'vue'
|
|
|
|
} from 'vue'
|
|
|
|
import { useMediaQuery } from '@vueuse/core'
|
|
|
|
import { useMediaQuery } from '@vueuse/core'
|
|
|
|
import { useRoute } from 'vitepress'
|
|
|
|
import { useRoute } from 'vitepress'
|
|
|
|
import type { DefaultTheme } from 'vitepress/theme'
|
|
|
|
import type { DefaultTheme } from 'vitepress/theme'
|
|
|
|
import { isActive } from '../../shared'
|
|
|
|
import { inBrowser, isActive } from '../../shared'
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
hasActiveLink as containsActiveLink,
|
|
|
|
hasActiveLink as containsActiveLink,
|
|
|
|
getSidebar,
|
|
|
|
getSidebar,
|
|
|
@ -22,7 +23,7 @@ export interface SidebarControl {
|
|
|
|
collapsed: Ref<boolean>
|
|
|
|
collapsed: Ref<boolean>
|
|
|
|
collapsible: ComputedRef<boolean>
|
|
|
|
collapsible: ComputedRef<boolean>
|
|
|
|
isLink: ComputedRef<boolean>
|
|
|
|
isLink: ComputedRef<boolean>
|
|
|
|
isActiveLink: ComputedRef<boolean>
|
|
|
|
isActiveLink: Ref<boolean>
|
|
|
|
hasActiveLink: ComputedRef<boolean>
|
|
|
|
hasActiveLink: ComputedRef<boolean>
|
|
|
|
hasChildren: ComputedRef<boolean>
|
|
|
|
hasChildren: ComputedRef<boolean>
|
|
|
|
toggle(): void
|
|
|
|
toggle(): void
|
|
|
@ -127,6 +128,13 @@ export function useCloseSidebarOnEscape(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hashRef = ref(inBrowser ? location.hash : '')
|
|
|
|
|
|
|
|
if (inBrowser) {
|
|
|
|
|
|
|
|
window.addEventListener('hashchange', () => {
|
|
|
|
|
|
|
|
hashRef.value = location.hash
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function useSidebarControl(
|
|
|
|
export function useSidebarControl(
|
|
|
|
item: ComputedRef<DefaultTheme.SidebarItem>
|
|
|
|
item: ComputedRef<DefaultTheme.SidebarItem>
|
|
|
|
): SidebarControl {
|
|
|
|
): SidebarControl {
|
|
|
@ -142,9 +150,13 @@ export function useSidebarControl(
|
|
|
|
return !!item.value.link
|
|
|
|
return !!item.value.link
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const isActiveLink = computed(() => {
|
|
|
|
const isActiveLink = ref(false)
|
|
|
|
return isActive(page.value.relativePath, item.value.link)
|
|
|
|
const updateIsActiveLink = () => {
|
|
|
|
})
|
|
|
|
isActiveLink.value = isActive(page.value.relativePath, item.value.link)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch([page, item, hashRef], updateIsActiveLink)
|
|
|
|
|
|
|
|
onMounted(updateIsActiveLink)
|
|
|
|
|
|
|
|
|
|
|
|
const hasActiveLink = computed(() => {
|
|
|
|
const hasActiveLink = computed(() => {
|
|
|
|
if (isActiveLink.value) {
|
|
|
|
if (isActiveLink.value) {
|
|
|
|