-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ZTL-UwU <zhangtianli2006@163.com>
- Loading branch information
Showing
12 changed files
with
160 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<div class="hidden xl:block"> | ||
<UiScrollArea orientation="vertical" class="h-[calc(100vh-6.5rem)] z-30 md:block overflow-y-auto" type="hover"> | ||
<p class="mb-2 text-base font-semibold"> | ||
On This Page | ||
</p> | ||
<LayoutTocTree :links="toc.links" :level="0" /> | ||
</UiScrollArea> | ||
</div> | ||
|
||
<div class="block xl:hidden mb-6"> | ||
<UiCollapsible> | ||
<UiCollapsibleTrigger> | ||
<UiButton variant="outline"> | ||
On This Page | ||
</UiButton> | ||
</UiCollapsibleTrigger> | ||
<UiCollapsibleContent class="text-sm mt-4 border-l pl-4"> | ||
<LayoutTocTree :links="toc.links" :level="0" /> | ||
</UiCollapsibleContent> | ||
</UiCollapsible> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const { toc } = useContent(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<ul :class="[level !== 0 && 'pl-4']"> | ||
<li v-for="link in links" :key="link.id" class="pt-2"> | ||
<NuxtLink | ||
:to="`#${link.id}`" | ||
class="text-muted-foreground hover:text-primary hover:font-medium transition-all" | ||
:class="[activeHeadings.includes(link.id) && 'text-primary font-medium']" | ||
> | ||
{{ link.text }} | ||
</NuxtLink> | ||
<TocTree v-if="link.children" :links="link.children" :level="level + 1" /> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { TocLink } from '@nuxt/content/types'; | ||
defineProps<{ | ||
links: TocLink[]; | ||
level: number; | ||
}>(); | ||
const { activeHeadings, updateHeadings } = useScrollspy(); | ||
onNuxtReady(() => | ||
updateHeadings([ | ||
...document.querySelectorAll('.docs-content h1'), | ||
...document.querySelectorAll('.docs-content h2'), | ||
...document.querySelectorAll('.docs-content h3'), | ||
...document.querySelectorAll('.docs-content h4'), | ||
]), | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<CollapsibleRoot v-slot="{ open }" v-bind="forwarded"> | ||
<slot :open="open" /> | ||
</CollapsibleRoot> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { CollapsibleRoot, useForwardPropsEmits } from 'radix-vue'; | ||
import type { CollapsibleRootEmits, CollapsibleRootProps } from 'radix-vue'; | ||
const props = defineProps<CollapsibleRootProps>(); | ||
const emits = defineEmits<CollapsibleRootEmits>(); | ||
const forwarded = useForwardPropsEmits(props, emits); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<CollapsibleContent v-bind="props" class="overflow-hidden transition-all data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down"> | ||
<slot /> | ||
</CollapsibleContent> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { CollapsibleContent, type CollapsibleContentProps } from 'radix-vue'; | ||
const props = defineProps<CollapsibleContentProps>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<CollapsibleTrigger v-bind="props"> | ||
<slot /> | ||
</CollapsibleTrigger> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { CollapsibleTrigger, type CollapsibleTriggerProps } from 'radix-vue'; | ||
const props = defineProps<CollapsibleTriggerProps>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as Collapsible } from './Collapsible.vue'; | ||
export { default as CollapsibleTrigger } from './CollapsibleTrigger.vue'; | ||
export { default as CollapsibleContent } from './CollapsibleContent.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Credit: nuxt-themes/docus | ||
|
||
import type { Ref } from 'vue'; | ||
|
||
/** | ||
* Scrollspy allows you to watch visible headings in a specific page. | ||
* Useful for table of contents live style updates. | ||
*/ | ||
export function useScrollspy() { | ||
const observer = ref() as Ref<IntersectionObserver>; | ||
const visibleHeadings = ref([]) as Ref<string[]>; | ||
const activeHeadings = ref([]) as Ref<string[]>; | ||
|
||
const observerCallback = (entries: IntersectionObserverEntry[]) => | ||
entries.forEach((entry) => { | ||
const id = entry.target.id; | ||
|
||
if (entry.isIntersecting) | ||
visibleHeadings.value.push(id); | ||
else visibleHeadings.value = visibleHeadings.value.filter(t => t !== id); | ||
}); | ||
|
||
const updateHeadings = (headings: Element[]) => | ||
headings.forEach((heading) => { | ||
observer.value.observe(heading); | ||
}); | ||
|
||
watch(visibleHeadings, (val, oldVal) => { | ||
if (val.length === 0) | ||
activeHeadings.value = oldVal; | ||
else activeHeadings.value = val; | ||
}, { deep: true }); | ||
|
||
// Create intersection observer | ||
onBeforeMount(() => (observer.value = new IntersectionObserver(observerCallback))); | ||
|
||
// Destroy it | ||
onBeforeUnmount(() => observer.value?.disconnect()); | ||
|
||
return { | ||
visibleHeadings, | ||
activeHeadings, | ||
updateHeadings, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ | |
"shiki": "^1.6.0", | ||
"vue-tsc": "^2.0.19" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters