File tree Expand file tree Collapse file tree 7 files changed +33
-10
lines changed Expand file tree Collapse file tree 7 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import VPNav from './components/VPNav.vue'
88import VPSidebar from ' ./components/VPSidebar.vue'
99import VPSkipLink from ' ./components/VPSkipLink.vue'
1010import { useData } from ' ./composables/data'
11- import { registerWatchers } from ' ./composables/layout'
11+ import { layoutInfoInjectionKey , registerWatchers } from ' ./composables/layout'
1212import { useSidebarControl } from ' ./composables/sidebar'
1313
1414const {
@@ -24,7 +24,7 @@ const { frontmatter } = useData()
2424const slots = useSlots ()
2525const heroImageSlotExists = computed (() => !! slots [' home-hero-image' ])
2626
27- provide (' hero-image-slot-exists ' , heroImageSlotExists )
27+ provide (layoutInfoInjectionKey , { heroImageSlotExists } )
2828 </script >
2929
3030<template >
Original file line number Diff line number Diff line change 11<script setup lang="ts">
2- import { type Ref , inject } from ' vue'
32import type { DefaultTheme } from ' vitepress/theme'
3+ import { inject } from ' vue'
4+ import { layoutInfoInjectionKey } from ' ../composables/layout'
45import VPButton from ' ./VPButton.vue'
56import VPImage from ' ./VPImage.vue'
67
@@ -20,7 +21,7 @@ defineProps<{
2021 actions? : HeroAction []
2122}>()
2223
23- const heroImageSlotExists = inject (' hero-image-slot-exists ' ) as Ref < boolean >
24+ const { heroImageSlotExists } = inject (layoutInfoInjectionKey ) !
2425 </script >
2526
2627<template >
Original file line number Diff line number Diff line change 22import { inBrowser } from ' vitepress'
33import { computed , provide , watchEffect } from ' vue'
44import { useData } from ' ../composables/data'
5- import { useNav } from ' ../composables/nav'
5+ import { navInjectionKey , useNav } from ' ../composables/nav'
66import VPNavBar from ' ./VPNavBar.vue'
77import VPNavScreen from ' ./VPNavScreen.vue'
88
@@ -13,7 +13,7 @@ const hasNavbar = computed(() => {
1313 return frontmatter .value .navbar !== false
1414})
1515
16- provide (' close-screen ' , closeScreen )
16+ provide (navInjectionKey , { closeScreen } )
1717
1818watchEffect (() => {
1919 if (inBrowser ) {
Original file line number Diff line number Diff line change 11<script lang="ts" setup>
22import type { DefaultTheme } from ' vitepress/theme'
33import { inject } from ' vue'
4+ import { navInjectionKey } from ' ../composables/nav'
45import VPLink from ' ./VPLink.vue'
56
67defineProps <{
78 item: DefaultTheme .NavItemWithLink
89}>()
910
10- const closeScreen = inject (' close-screen ' ) as () => void
11+ const { closeScreen } = inject (navInjectionKey ) !
1112 </script >
1213
1314<template >
Original file line number Diff line number Diff line change 11<script lang="ts" setup>
22import type { DefaultTheme } from ' vitepress/theme'
33import { inject } from ' vue'
4+ import { navInjectionKey } from ' ../composables/nav'
45import VPLink from ' ./VPLink.vue'
56
67defineProps <{
78 item: DefaultTheme .NavItemWithLink
89}>()
910
10- const closeScreen = inject (' close-screen ' ) as () => void
11+ const { closeScreen } = inject (navInjectionKey ) !
1112 </script >
1213
1314<template >
Original file line number Diff line number Diff line change 11import { inBrowser , onContentUpdated , useRoute } from 'vitepress'
22import type { DefaultTheme , useLayout as expected } from 'vitepress/theme'
3- import { computed , shallowReadonly , shallowRef , watch } from 'vue'
3+ import {
4+ computed ,
5+ shallowReadonly ,
6+ shallowRef ,
7+ watch ,
8+ type ComputedRef ,
9+ type InjectionKey
10+ } from 'vue'
411import { getSidebar , getSidebarGroups } from '../support/sidebar'
512import { useData } from './data'
613import { getHeaders } from './outline'
@@ -102,3 +109,10 @@ export function registerWatchers({ closeSidebar }: RegisterWatchersOptions) {
102109
103110 useCloseSidebarOnEscape ( closeSidebar )
104111}
112+
113+ export interface LayoutInfo {
114+ heroImageSlotExists : ComputedRef < boolean >
115+ }
116+
117+ export const layoutInfoInjectionKey : InjectionKey < LayoutInfo > =
118+ Symbol ( 'layout-info' )
Original file line number Diff line number Diff line change 11import { useRoute } from 'vitepress'
2- import { ref , watch } from 'vue'
2+ import { ref , watch , type InjectionKey } from 'vue'
33
44export function useNav ( ) {
55 const isScreenOpen = ref ( false )
@@ -35,3 +35,9 @@ export function useNav() {
3535 toggleScreen
3636 }
3737}
38+
39+ export interface NavExposedMethods {
40+ closeScreen : ( ) => void
41+ }
42+
43+ export const navInjectionKey : InjectionKey < NavExposedMethods > = Symbol ( 'nav' )
You can’t perform that action at this time.
0 commit comments