@verbb/vitepress-theme 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/package.json +32 -0
- package/src/Layout.vue +1077 -0
- package/src/components/DocsIcon.vue +100 -0
- package/src/components/DocsMobileMenu.vue +68 -0
- package/src/components/DocsMobileMenuNode.vue +114 -0
- package/src/components/DocsNotFound.vue +41 -0
- package/src/components/DocsOutline.vue +284 -0
- package/src/components/DocsOutlineItem.vue +65 -0
- package/src/components/DocsSearchProvider.vue +51 -0
- package/src/components/DocsSidebar.vue +41 -0
- package/src/components/DocsSidebarNode.vue +114 -0
- package/src/custom.css +547 -0
- package/src/env.d.ts +8 -0
- package/src/index.ts +22 -0
- package/src/search.ts +17 -0
- package/src/sidebar.ts +218 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, onUnmounted, ref } from 'vue';
|
|
3
|
+
import VPLocalSearchBox from 'vitepress/dist/client/theme-default/components/VPLocalSearchBox.vue';
|
|
4
|
+
import { registerDocsSearch, unregisterDocsSearch } from '../search';
|
|
5
|
+
|
|
6
|
+
const showSearch = ref(false);
|
|
7
|
+
|
|
8
|
+
function openSearch() {
|
|
9
|
+
showSearch.value = true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function closeSearch() {
|
|
13
|
+
showSearch.value = false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isEditingContent(event: KeyboardEvent) {
|
|
17
|
+
const element = event.target as HTMLElement;
|
|
18
|
+
const tagName = element.tagName;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
element.isContentEditable
|
|
22
|
+
|| tagName === 'INPUT'
|
|
23
|
+
|| tagName === 'SELECT'
|
|
24
|
+
|| tagName === 'TEXTAREA'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function handleSearchHotKey(event: KeyboardEvent) {
|
|
29
|
+
if (
|
|
30
|
+
(event.key.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey))
|
|
31
|
+
|| (!isEditingContent(event) && event.key === '/')
|
|
32
|
+
) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
openSearch();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
onMounted(() => {
|
|
39
|
+
registerDocsSearch(openSearch);
|
|
40
|
+
window.addEventListener('keydown', handleSearchHotKey);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
onUnmounted(() => {
|
|
44
|
+
unregisterDocsSearch(openSearch);
|
|
45
|
+
window.removeEventListener('keydown', handleSearchHotKey);
|
|
46
|
+
});
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<VPLocalSearchBox v-if="showSearch" @close="closeSearch" />
|
|
51
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { useDocsSidebar } from '../sidebar';
|
|
4
|
+
import DocsIcon from './DocsIcon.vue';
|
|
5
|
+
import DocsSidebarNode from './DocsSidebarNode.vue';
|
|
6
|
+
|
|
7
|
+
defineEmits<{
|
|
8
|
+
navigate: [];
|
|
9
|
+
}>();
|
|
10
|
+
|
|
11
|
+
const { sidebarGroups } = useDocsSidebar();
|
|
12
|
+
|
|
13
|
+
const groups = computed(() => sidebarGroups.value.filter((group) => group.items?.length));
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<nav aria-label="Sidebar navigation" class="text-sm">
|
|
18
|
+
<section v-for="group in groups" :key="group.text ?? group.items?.[0]?.link" class="mt-6 first:mt-0 lg:mt-6 lg:first:mt-0">
|
|
19
|
+
<h2
|
|
20
|
+
v-if="group.text"
|
|
21
|
+
class="mb-3 flex items-center gap-2.5 text-sm font-medium text-slate-900 lg:mb-2"
|
|
22
|
+
>
|
|
23
|
+
<DocsIcon
|
|
24
|
+
v-if="group.icon"
|
|
25
|
+
:name="group.icon"
|
|
26
|
+
class="size-4 text-slate-600"
|
|
27
|
+
/>
|
|
28
|
+
{{ group.text }}
|
|
29
|
+
</h2>
|
|
30
|
+
|
|
31
|
+
<ul class="space-y-px">
|
|
32
|
+
<DocsSidebarNode
|
|
33
|
+
v-for="item in group.items"
|
|
34
|
+
:key="item.link ?? `${item.text}-${item.icon ?? ''}`"
|
|
35
|
+
:item="item"
|
|
36
|
+
@navigate="$emit('navigate')"
|
|
37
|
+
/>
|
|
38
|
+
</ul>
|
|
39
|
+
</section>
|
|
40
|
+
</nav>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from 'vue';
|
|
3
|
+
import { useData, useRouter, withBase } from 'vitepress';
|
|
4
|
+
import type { SidebarItem } from '../sidebar';
|
|
5
|
+
import { hasActiveSidebarItem, isActivePath } from '../sidebar';
|
|
6
|
+
import DocsIcon from './DocsIcon.vue';
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{
|
|
9
|
+
item: SidebarItem;
|
|
10
|
+
depth?: number;
|
|
11
|
+
}>(), {
|
|
12
|
+
depth: 0,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const emit = defineEmits<{
|
|
16
|
+
navigate: [];
|
|
17
|
+
}>();
|
|
18
|
+
|
|
19
|
+
const { page } = useData();
|
|
20
|
+
const router = useRouter();
|
|
21
|
+
|
|
22
|
+
const hasChildren = computed(() => Boolean(props.item.items?.length));
|
|
23
|
+
const isCurrent = computed(() => isActivePath(page.value.relativePath, props.item.link));
|
|
24
|
+
const hasActiveDescendant = computed(() => {
|
|
25
|
+
return props.item.items?.some((child) => hasActiveSidebarItem(page.value.relativePath, child)) ?? false;
|
|
26
|
+
});
|
|
27
|
+
const isOpen = ref(hasChildren.value ? (!props.item.collapsed || hasActiveDescendant.value) : false);
|
|
28
|
+
|
|
29
|
+
watch(hasActiveDescendant, (value) => {
|
|
30
|
+
if (value) {
|
|
31
|
+
isOpen.value = true;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
function itemHref(link?: string) {
|
|
36
|
+
return link ? withBase(link) : '#';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function navigate(event: MouseEvent, link?: string) {
|
|
40
|
+
if (!link) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
await router.go(itemHref(link));
|
|
46
|
+
emit('navigate');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function toggleGroup() {
|
|
50
|
+
if (!hasChildren.value) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
isOpen.value = !isOpen.value;
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<li class="relative">
|
|
60
|
+
<button
|
|
61
|
+
v-if="hasChildren"
|
|
62
|
+
type="button"
|
|
63
|
+
class="group flex w-full cursor-pointer items-center py-0.5 pr-2 text-left text-sm leading-6 outline-offset-[-1px] transition hover:text-docs-primary"
|
|
64
|
+
:class="hasActiveDescendant
|
|
65
|
+
? 'text-docs-primary'
|
|
66
|
+
: 'text-slate-700'"
|
|
67
|
+
@click="toggleGroup"
|
|
68
|
+
>
|
|
69
|
+
<span class="min-w-0 flex-1 break-words">{{ item.text }}</span>
|
|
70
|
+
<svg
|
|
71
|
+
viewBox="0 0 640 640"
|
|
72
|
+
class="size-3 shrink-0"
|
|
73
|
+
:class="isOpen ? 'rotate-90' : 'rotate-0'"
|
|
74
|
+
aria-hidden="true"
|
|
75
|
+
>
|
|
76
|
+
<path d="M471.1 297.4C483.6 309.9 483.6 330.2 471.1 342.7L279.1 534.7C266.6 547.2 246.3 547.2 233.8 534.7C221.3 522.2 221.3 501.9 233.8 489.4L403.2 320L233.9 150.6C221.4 138.1 221.4 117.8 233.9 105.3C246.4 92.8 266.7 92.8 279.2 105.3L471.2 297.3z" />
|
|
77
|
+
</svg>
|
|
78
|
+
</button>
|
|
79
|
+
|
|
80
|
+
<a
|
|
81
|
+
v-else
|
|
82
|
+
:href="itemHref(item.link)"
|
|
83
|
+
class="group flex w-full cursor-pointer items-center py-0.5 text-left text-sm leading-6 outline-offset-[-1px] transition hover:text-docs-primary"
|
|
84
|
+
:class="isCurrent
|
|
85
|
+
? 'text-docs-primary'
|
|
86
|
+
: 'text-slate-700'"
|
|
87
|
+
@click="navigate($event, item.link)"
|
|
88
|
+
>
|
|
89
|
+
<div class="flex min-w-0 flex-1 items-start gap-x-2.5">
|
|
90
|
+
<DocsIcon
|
|
91
|
+
v-if="item.icon"
|
|
92
|
+
:name="item.icon"
|
|
93
|
+
class="mt-1 size-4 shrink-0 text-slate-500 group-hover:text-slate-700"
|
|
94
|
+
/>
|
|
95
|
+
<div class="flex min-w-0 flex-1 flex-wrap items-center gap-1.5 [word-break:break-word]">
|
|
96
|
+
<span class="min-w-0 max-w-full break-words">{{ item.text }}</span>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</a>
|
|
100
|
+
|
|
101
|
+
<ul
|
|
102
|
+
v-if="hasChildren && isOpen"
|
|
103
|
+
:style="{ marginLeft: depth === 0 ? '1rem' : '1.25rem' }"
|
|
104
|
+
>
|
|
105
|
+
<DocsSidebarNode
|
|
106
|
+
v-for="child in item.items"
|
|
107
|
+
:key="child.link ?? `${child.text}-${child.icon ?? ''}`"
|
|
108
|
+
:item="child"
|
|
109
|
+
:depth="depth + 1"
|
|
110
|
+
@navigate="emit('navigate')"
|
|
111
|
+
/>
|
|
112
|
+
</ul>
|
|
113
|
+
</li>
|
|
114
|
+
</template>
|