|
|
@ -1,42 +1,44 @@
|
|
|
|
import { computed, watch } from 'vue'
|
|
|
|
import { ref, watch } from 'vue'
|
|
|
|
import { useInert, useRoute } from 'vitepress'
|
|
|
|
import { useInert, useRoute } from 'vitepress'
|
|
|
|
|
|
|
|
import { useMediaQuery } from '@vueuse/core'
|
|
|
|
|
|
|
|
|
|
|
|
export function useNav() {
|
|
|
|
export function useNav() {
|
|
|
|
const inert = useInert()!
|
|
|
|
const inert = useInert()!
|
|
|
|
const isScreenOpen = computed(() => inert.isScreenOpen)
|
|
|
|
const is768 = useMediaQuery('(min-width: 768px)')
|
|
|
|
|
|
|
|
const isScreenOpen = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
function openScreen() {
|
|
|
|
function openScreen() {
|
|
|
|
inert.isScreenOpen = true
|
|
|
|
isScreenOpen.value = true
|
|
|
|
window.addEventListener('resize', closeScreenOnTabletWindow)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleCloseScreen(fromRoute = false) {
|
|
|
|
|
|
|
|
if (fromRoute) inert.onAfterRouteChanged()
|
|
|
|
|
|
|
|
else inert.isScreenOpen = false
|
|
|
|
|
|
|
|
window.removeEventListener('resize', closeScreenOnTabletWindow)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function closeScreen() {
|
|
|
|
function closeScreen() {
|
|
|
|
handleCloseScreen()
|
|
|
|
isScreenOpen.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toggleScreen() {
|
|
|
|
function toggleScreen() {
|
|
|
|
isScreenOpen.value ? handleCloseScreen() : openScreen()
|
|
|
|
isScreenOpen.value ? closeScreen() : openScreen()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
watch(is768, (mq) => {
|
|
|
|
* Close the screen when the user resizes the window wider than tablet size.
|
|
|
|
if (mq) {
|
|
|
|
*/
|
|
|
|
isScreenOpen.value = false
|
|
|
|
function closeScreenOnTabletWindow() {
|
|
|
|
}
|
|
|
|
window.outerWidth >= 768 && handleCloseScreen()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
|
|
watch(
|
|
|
|
watch(
|
|
|
|
() => route.path,
|
|
|
|
() => [isScreenOpen.value, is768.value],
|
|
|
|
() => handleCloseScreen(true)
|
|
|
|
([screenOpen, mq]) => {
|
|
|
|
|
|
|
|
if (mq) {
|
|
|
|
|
|
|
|
inert.isScreenOpen = false
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
inert.isScreenOpen = screenOpen
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
|
|
watch(() => route.path, closeScreen)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
isScreenOpen,
|
|
|
|
isScreenOpen,
|
|
|
|
openScreen,
|
|
|
|
openScreen,
|
|
|
|