|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { ref } from 'vue' |
3 | 2 | import { useData } from 'vitepress'
|
| 3 | +import type { DefaultTheme } from 'vitepress/theme' |
| 4 | +import { computed, inject, ref, type Ref } from 'vue' |
4 | 5 | import {
|
5 |
| - useOutline, |
6 |
| - useActiveAnchor |
| 6 | + getHeaders, |
| 7 | + useActiveAnchor, |
| 8 | + type MenuItem |
7 | 9 | } from '../composables/outline.js'
|
| 10 | +import VPDocAsideOutlineItem from './VPDocAsideOutlineItem.vue' |
8 | 11 |
|
9 |
| -const { page, frontmatter, theme } = useData() |
| 12 | +const { frontmatter, theme } = useData() |
10 | 13 |
|
11 |
| -const { hasOutline } = useOutline() |
| 14 | +const pageOutline = computed<DefaultTheme.Config['outline']>( |
| 15 | + () => frontmatter.value.outline ?? theme.value.outline |
| 16 | +) |
| 17 | +
|
| 18 | +const onContentUpdated = inject('onContentUpdated') as Ref<() => void> |
| 19 | +onContentUpdated.value = () => { |
| 20 | + headers.value = getHeaders(pageOutline.value) |
| 21 | +} |
| 22 | +
|
| 23 | +const headers = ref<MenuItem[]>([]) |
| 24 | +const hasOutline = computed(() => headers.value.length > 0) |
12 | 25 |
|
13 | 26 | const container = ref()
|
14 | 27 | const marker = ref()
|
@@ -37,23 +50,7 @@ function handleClick({ target: el }: Event) {
|
37 | 50 | <span class="visually-hidden" id="doc-outline-aria-label">
|
38 | 51 | Table of Contents for current page
|
39 | 52 | </span>
|
40 |
| - |
41 |
| - <ul class="root"> |
42 |
| - <li |
43 |
| - v-for="{ title, link, children } in page.headers" |
44 |
| - > |
45 |
| - <a class="outline-link" :href="link" @click="handleClick"> |
46 |
| - {{ title }} |
47 |
| - </a> |
48 |
| - <ul v-if="children && frontmatter.outline === 'deep'"> |
49 |
| - <li v-for="{ title, link } in children"> |
50 |
| - <a class="outline-link nested" :href="link" @click="handleClick"> |
51 |
| - {{ title }} |
52 |
| - </a> |
53 |
| - </li> |
54 |
| - </ul> |
55 |
| - </li> |
56 |
| - </ul> |
| 53 | + <VPDocAsideOutlineItem :headers="headers" :root="true" :onClick="handleClick" /> |
57 | 54 | </nav>
|
58 | 55 | </div>
|
59 | 56 | </div>
|
@@ -94,29 +91,4 @@ function handleClick({ target: el }: Event) {
|
94 | 91 | font-size: 13px;
|
95 | 92 | font-weight: 600;
|
96 | 93 | }
|
97 |
| -
|
98 |
| -.outline-link { |
99 |
| - display: block; |
100 |
| - line-height: 28px; |
101 |
| - color: var(--vp-c-text-2); |
102 |
| - white-space: nowrap; |
103 |
| - overflow: hidden; |
104 |
| - text-overflow: ellipsis; |
105 |
| - transition: color 0.5s; |
106 |
| -} |
107 |
| -
|
108 |
| -.outline-link:hover, |
109 |
| -.outline-link.active { |
110 |
| - color: var(--vp-c-text-1); |
111 |
| - transition: color 0.25s; |
112 |
| -} |
113 |
| -
|
114 |
| -.outline-link.nested { |
115 |
| - padding-left: 13px; |
116 |
| -} |
117 |
| -
|
118 |
| -.root { |
119 |
| - position: relative; |
120 |
| - z-index: 1; |
121 |
| -} |
122 | 94 | </style>
|
0 commit comments