|
|
@ -1,4 +1,3 @@
|
|
|
|
import { useMediaQuery } from '@vueuse/core'
|
|
|
|
|
|
|
|
import type { DefaultTheme } from 'vitepress/theme'
|
|
|
|
import type { DefaultTheme } from 'vitepress/theme'
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
computed,
|
|
|
@ -12,13 +11,8 @@ import {
|
|
|
|
type Ref
|
|
|
|
type Ref
|
|
|
|
} from 'vue'
|
|
|
|
} from 'vue'
|
|
|
|
import { isActive } from '../../shared'
|
|
|
|
import { isActive } from '../../shared'
|
|
|
|
import {
|
|
|
|
import { hasActiveLink as containsActiveLink } from '../support/sidebar'
|
|
|
|
hasActiveLink as containsActiveLink,
|
|
|
|
|
|
|
|
getSidebar,
|
|
|
|
|
|
|
|
getSidebarGroups
|
|
|
|
|
|
|
|
} from '../support/sidebar'
|
|
|
|
|
|
|
|
import { useData } from './data'
|
|
|
|
import { useData } from './data'
|
|
|
|
import { useLayout } from './layout'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface SidebarControl {
|
|
|
|
export interface SidebarControl {
|
|
|
|
collapsed: Ref<boolean>
|
|
|
|
collapsed: Ref<boolean>
|
|
|
@ -30,80 +24,6 @@ export interface SidebarControl {
|
|
|
|
toggle(): void
|
|
|
|
toggle(): void
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function useSidebar() {
|
|
|
|
|
|
|
|
const { frontmatter, page, theme } = useData()
|
|
|
|
|
|
|
|
const { isHome } = useLayout()
|
|
|
|
|
|
|
|
const is960 = useMediaQuery('(min-width: 960px)')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isOpen = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const _sidebar = computed(() => {
|
|
|
|
|
|
|
|
const sidebarConfig = theme.value.sidebar
|
|
|
|
|
|
|
|
const relativePath = page.value.relativePath
|
|
|
|
|
|
|
|
return sidebarConfig ? getSidebar(sidebarConfig, relativePath) : []
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sidebar = ref(_sidebar.value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch(_sidebar, (next, prev) => {
|
|
|
|
|
|
|
|
if (JSON.stringify(next) !== JSON.stringify(prev))
|
|
|
|
|
|
|
|
sidebar.value = _sidebar.value
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hasSidebar = computed(() => {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
frontmatter.value.sidebar !== false &&
|
|
|
|
|
|
|
|
sidebar.value.length > 0 &&
|
|
|
|
|
|
|
|
!isHome.value
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const leftAside = computed(() => {
|
|
|
|
|
|
|
|
if (hasAside)
|
|
|
|
|
|
|
|
return frontmatter.value.aside == null
|
|
|
|
|
|
|
|
? theme.value.aside === 'left'
|
|
|
|
|
|
|
|
: frontmatter.value.aside === 'left'
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hasAside = computed(() => {
|
|
|
|
|
|
|
|
if (isHome.value) return false
|
|
|
|
|
|
|
|
if (frontmatter.value.aside != null) return !!frontmatter.value.aside
|
|
|
|
|
|
|
|
return theme.value.aside !== false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isSidebarEnabled = computed(() => hasSidebar.value && is960.value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sidebarGroups = computed(() => {
|
|
|
|
|
|
|
|
return hasSidebar.value ? getSidebarGroups(sidebar.value) : []
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function open() {
|
|
|
|
|
|
|
|
isOpen.value = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toggle() {
|
|
|
|
|
|
|
|
isOpen.value ? close() : open()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
isOpen,
|
|
|
|
|
|
|
|
sidebar,
|
|
|
|
|
|
|
|
sidebarGroups,
|
|
|
|
|
|
|
|
hasSidebar,
|
|
|
|
|
|
|
|
hasAside,
|
|
|
|
|
|
|
|
leftAside,
|
|
|
|
|
|
|
|
isSidebarEnabled,
|
|
|
|
|
|
|
|
open,
|
|
|
|
|
|
|
|
close,
|
|
|
|
|
|
|
|
toggle
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* a11y: cache the element that opened the Sidebar (the menu button) then
|
|
|
|
* a11y: cache the element that opened the Sidebar (the menu button) then
|
|
|
|
* focus that button again when Menu is closed with Escape key.
|
|
|
|
* focus that button again when Menu is closed with Escape key.
|
|
|
@ -136,7 +56,30 @@ export function useCloseSidebarOnEscape(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function useSidebarControl(
|
|
|
|
export function useSidebarControl() {
|
|
|
|
|
|
|
|
const isOpen = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function open() {
|
|
|
|
|
|
|
|
isOpen.value = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function toggle() {
|
|
|
|
|
|
|
|
isOpen.value ? close() : open()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
isOpen,
|
|
|
|
|
|
|
|
open,
|
|
|
|
|
|
|
|
close,
|
|
|
|
|
|
|
|
toggle
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function useSidebarItemControl(
|
|
|
|
item: ComputedRef<DefaultTheme.SidebarItem>
|
|
|
|
item: ComputedRef<DefaultTheme.SidebarItem>
|
|
|
|
): SidebarControl {
|
|
|
|
): SidebarControl {
|
|
|
|
const { page, hash } = useData()
|
|
|
|
const { page, hash } = useData()
|
|
|
|