@vuepress/theme-default 2.0.0-beta.8 → 2.0.0-rc.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/lib/client/components/AutoLink.vue +119 -0
- package/lib/client/components/DropdownTransition.vue +15 -24
- package/lib/client/components/Home.vue +12 -130
- package/lib/client/components/HomeContent.vue +5 -0
- package/lib/client/components/HomeFeatures.vue +23 -0
- package/lib/client/components/HomeFooter.vue +17 -0
- package/lib/client/components/HomeHero.vue +98 -0
- package/lib/client/components/Navbar.vue +60 -95
- package/lib/client/components/NavbarBrand.vue +55 -0
- package/lib/client/components/NavbarDropdown.vue +126 -0
- package/lib/client/components/{NavbarLinks.vue → NavbarItems.vue} +73 -58
- package/lib/client/components/Page.vue +16 -15
- package/lib/client/components/PageMeta.vue +51 -66
- package/lib/client/components/PageNav.vue +47 -60
- package/lib/client/components/Sidebar.vue +12 -32
- package/lib/client/components/SidebarItem.vue +87 -0
- package/lib/client/components/SidebarItems.vue +57 -0
- package/lib/client/components/ToggleColorModeButton.vue +57 -0
- package/lib/client/components/ToggleSidebarButton.vue +21 -24
- package/lib/client/components/global/Badge.vue +24 -26
- package/lib/client/components/global/CodeGroup.d.ts +5 -4
- package/lib/client/components/global/CodeGroup.js +85 -17
- package/lib/client/components/global/CodeGroupItem.vue +23 -17
- package/lib/client/components/global/index.d.ts +4 -0
- package/lib/client/components/global/index.js +4 -0
- package/lib/client/composables/index.d.ts +7 -5
- package/lib/client/composables/index.js +7 -5
- package/lib/client/composables/useDarkMode.d.ts +12 -0
- package/lib/client/composables/useDarkMode.js +57 -0
- package/lib/client/composables/useNavLink.d.ts +6 -1
- package/lib/client/composables/useNavLink.js +5 -2
- package/lib/client/composables/useResolveRouteWithRedirect.js +2 -2
- package/lib/client/composables/useScrollPromise.js +1 -1
- package/lib/client/composables/useSidebarItems.d.ts +13 -8
- package/lib/client/composables/useSidebarItems.js +42 -38
- package/lib/client/composables/useThemeData.d.ts +2 -2
- package/lib/client/composables/useThemeData.js +1 -1
- package/lib/client/composables/useUpdateDeviceStatus.d.ts +7 -0
- package/lib/client/composables/useUpdateDeviceStatus.js +25 -0
- package/lib/client/config.d.ts +3 -0
- package/lib/client/config.js +44 -0
- package/lib/client/index.d.ts +3 -4
- package/lib/client/index.js +3 -2
- package/lib/client/layouts/Layout.vue +133 -136
- package/lib/client/layouts/NotFound.vue +27 -0
- package/lib/client/shim.d.ts +5 -0
- package/lib/client/styles/{_wrapper.scss → _mixins.scss} +7 -2
- package/lib/client/styles/_variables.module.scss +5 -0
- package/lib/client/styles/_variables.scss +0 -28
- package/lib/client/styles/arrow.scss +4 -6
- package/lib/client/styles/badge.scss +14 -11
- package/lib/client/styles/code-group.scss +9 -2
- package/lib/client/styles/code.scss +35 -49
- package/lib/client/styles/custom-container.scss +82 -18
- package/lib/client/styles/home.scss +32 -24
- package/lib/client/styles/index.scss +4 -4
- package/lib/client/styles/layout.scss +82 -73
- package/lib/client/styles/{dropdown.scss → navbar-dropdown.scss} +36 -50
- package/lib/client/styles/navbar.scss +106 -50
- package/lib/client/styles/normalize.scss +200 -0
- package/lib/client/styles/page.scss +24 -8
- package/lib/client/styles/sidebar.scss +69 -87
- package/lib/client/styles/transitions.scss +13 -4
- package/lib/client/styles/vars-dark.scss +68 -0
- package/lib/client/styles/vars.scss +149 -0
- package/lib/client/utils/index.d.ts +3 -2
- package/lib/client/utils/index.js +3 -2
- package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
- package/lib/client/utils/isActiveSidebarItem.js +20 -0
- package/lib/client/utils/resolveEditLink.d.ts +2 -2
- package/lib/client/utils/resolveEditLink.js +15 -9
- package/lib/client/utils/resolveRepoType.d.ts +1 -1
- package/lib/client/utils/resolveRepoType.js +3 -1
- package/lib/node/defaultTheme.d.ts +4 -4
- package/lib/node/defaultTheme.js +111 -48
- package/lib/node/index.d.ts +4 -4
- package/lib/node/index.js +5 -17
- package/lib/node/utils/assignDefaultLocaleOptions.d.ts +4 -2
- package/lib/node/utils/assignDefaultLocaleOptions.js +13 -13
- package/lib/node/utils/index.d.ts +2 -5
- package/lib/node/utils/index.js +2 -17
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +2 -20
- package/lib/node/utils/resolveContainerPluginOptions.js +4 -66
- package/lib/shared/index.d.ts +3 -3
- package/lib/shared/index.js +3 -15
- package/lib/shared/nav.d.ts +16 -18
- package/lib/shared/nav.js +1 -2
- package/lib/shared/options.d.ts +51 -6
- package/lib/shared/options.js +1 -2
- package/lib/shared/page.d.ts +15 -6
- package/lib/shared/page.js +1 -2
- package/package.json +49 -29
- package/templates/build.html +34 -0
- package/CHANGELOG.md +0 -403
- package/lib/client/clientAppEnhance.d.ts +0 -3
- package/lib/client/clientAppEnhance.js +0 -30
- package/lib/client/clientAppSetup.d.ts +0 -2
- package/lib/client/clientAppSetup.js +0 -11
- package/lib/client/components/DropdownLink.vue +0 -141
- package/lib/client/components/NavLink.vue +0 -115
- package/lib/client/components/SidebarChild.d.ts +0 -6
- package/lib/client/components/SidebarChild.js +0 -91
- package/lib/client/components/global/OutboundLink.vue +0 -30
- package/lib/client/layouts/404.vue +0 -38
- package/lib/client/styles/_normalize.scss +0 -148
- package/lib/client/styles/plugins.scss +0 -18
- package/lib/client/styles/sr-only.scss +0 -12
- package/lib/node/utils/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
- package/lib/node/utils/resolveActiveHeaderLinksPluginOptions.js +0 -16
- package/lib/node/utils/resolveGitPluginOptions.d.ts +0 -6
- package/lib/node/utils/resolveGitPluginOptions.js +0 -22
- package/lib/node/utils/resolveMediumZoomPluginOptions.d.ts +0 -6
- package/lib/node/utils/resolveMediumZoomPluginOptions.js +0 -17
|
@@ -1,38 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import NavbarItems from '@theme/NavbarItems.vue'
|
|
3
|
+
import SidebarItems from '@theme/SidebarItems.vue'
|
|
4
|
+
|
|
5
|
+
defineSlots<{
|
|
6
|
+
top?: (props: Record<never, never>) => any
|
|
7
|
+
bottom?: (props: Record<never, never>) => any
|
|
8
|
+
}>()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
1
11
|
<template>
|
|
2
12
|
<aside class="sidebar">
|
|
3
|
-
<
|
|
4
|
-
|
|
13
|
+
<NavbarItems />
|
|
5
14
|
<slot name="top" />
|
|
6
|
-
|
|
7
|
-
<ul class="sidebar-links">
|
|
8
|
-
<template v-for="item in sidebarItems" :key="item.link || item.text">
|
|
9
|
-
<SidebarChild :item="item" />
|
|
10
|
-
</template>
|
|
11
|
-
</ul>
|
|
12
|
-
|
|
15
|
+
<SidebarItems />
|
|
13
16
|
<slot name="bottom" />
|
|
14
17
|
</aside>
|
|
15
18
|
</template>
|
|
16
|
-
|
|
17
|
-
<script lang="ts">
|
|
18
|
-
import { defineComponent } from 'vue'
|
|
19
|
-
import { useSidebarItems } from '../composables'
|
|
20
|
-
import NavbarLinks from './NavbarLinks.vue'
|
|
21
|
-
import { SidebarChild } from './SidebarChild'
|
|
22
|
-
|
|
23
|
-
export default defineComponent({
|
|
24
|
-
name: 'Sidebar',
|
|
25
|
-
|
|
26
|
-
components: {
|
|
27
|
-
NavbarLinks,
|
|
28
|
-
SidebarChild,
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
setup() {
|
|
32
|
-
const sidebarItems = useSidebarItems()
|
|
33
|
-
return {
|
|
34
|
-
sidebarItems,
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
</script>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import AutoLink from '@theme/AutoLink.vue'
|
|
3
|
+
import DropdownTransition from '@theme/DropdownTransition.vue'
|
|
4
|
+
import { useToggle } from '@vueuse/core'
|
|
5
|
+
import { computed, nextTick, onBeforeUnmount, toRefs } from 'vue'
|
|
6
|
+
import type { PropType } from 'vue'
|
|
7
|
+
import { useRoute, useRouter } from 'vue-router'
|
|
8
|
+
import type { ResolvedSidebarItem } from '../../shared/index.js'
|
|
9
|
+
import { isActiveSidebarItem } from '../utils/index.js'
|
|
10
|
+
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
item: {
|
|
13
|
+
type: Object as PropType<ResolvedSidebarItem>,
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
depth: {
|
|
17
|
+
type: Number,
|
|
18
|
+
required: false,
|
|
19
|
+
default: 0,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const { item, depth } = toRefs(props)
|
|
24
|
+
const route = useRoute()
|
|
25
|
+
const router = useRouter()
|
|
26
|
+
|
|
27
|
+
const isActive = computed(() => isActiveSidebarItem(item.value, route))
|
|
28
|
+
const itemClass = computed(() => ({
|
|
29
|
+
'sidebar-item': true,
|
|
30
|
+
'sidebar-heading': depth.value === 0,
|
|
31
|
+
'active': isActive.value,
|
|
32
|
+
'collapsible': item.value.collapsible,
|
|
33
|
+
}))
|
|
34
|
+
|
|
35
|
+
const isOpenDefault = computed(() =>
|
|
36
|
+
item.value.collapsible ? isActive.value : true,
|
|
37
|
+
)
|
|
38
|
+
const [isOpen, toggleIsOpen] = useToggle(isOpenDefault.value)
|
|
39
|
+
const onClick = (e: Event): void => {
|
|
40
|
+
if (item.value.collapsible) {
|
|
41
|
+
e.preventDefault()
|
|
42
|
+
// toggle open status on click
|
|
43
|
+
toggleIsOpen()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// reset open status after navigation
|
|
48
|
+
const unregisterRouterHook = router.afterEach((to) => {
|
|
49
|
+
nextTick(() => {
|
|
50
|
+
isOpen.value = isOpenDefault.value
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
onBeforeUnmount(() => {
|
|
54
|
+
unregisterRouterHook()
|
|
55
|
+
})
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<li>
|
|
60
|
+
<AutoLink v-if="item.link" :class="itemClass" :item="item" />
|
|
61
|
+
<p
|
|
62
|
+
v-else
|
|
63
|
+
tabindex="0"
|
|
64
|
+
:class="itemClass"
|
|
65
|
+
@click="onClick"
|
|
66
|
+
@keydown.enter="onClick"
|
|
67
|
+
>
|
|
68
|
+
{{ item.text }}
|
|
69
|
+
<span
|
|
70
|
+
v-if="item.collapsible"
|
|
71
|
+
class="arrow"
|
|
72
|
+
:class="isOpen ? 'down' : 'right'"
|
|
73
|
+
/>
|
|
74
|
+
</p>
|
|
75
|
+
|
|
76
|
+
<DropdownTransition v-if="item.children?.length">
|
|
77
|
+
<ul v-show="isOpen" class="sidebar-item-children">
|
|
78
|
+
<SidebarItem
|
|
79
|
+
v-for="child in item.children"
|
|
80
|
+
:key="`${depth}${child.text}${child.link}`"
|
|
81
|
+
:item="child"
|
|
82
|
+
:depth="depth + 1"
|
|
83
|
+
/>
|
|
84
|
+
</ul>
|
|
85
|
+
</DropdownTransition>
|
|
86
|
+
</li>
|
|
87
|
+
</template>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import SidebarItem from '@theme/SidebarItem.vue'
|
|
3
|
+
import { onMounted, watch } from 'vue'
|
|
4
|
+
import { useRoute } from 'vue-router'
|
|
5
|
+
import { useSidebarItems } from '../composables/index.js'
|
|
6
|
+
|
|
7
|
+
const route = useRoute()
|
|
8
|
+
const sidebarItems = useSidebarItems()
|
|
9
|
+
|
|
10
|
+
onMounted(() => {
|
|
11
|
+
watch(
|
|
12
|
+
() => route.hash,
|
|
13
|
+
(hash) => {
|
|
14
|
+
// get the sidebar DOM
|
|
15
|
+
const sidebar = document.querySelector('.sidebar')
|
|
16
|
+
if (!sidebar) return
|
|
17
|
+
|
|
18
|
+
// get the active sidebar item DOM, whose href equals to the current route
|
|
19
|
+
const activeSidebarItem = document.querySelector(
|
|
20
|
+
`.sidebar a.sidebar-item[href="${route.path}${hash}"]`,
|
|
21
|
+
)
|
|
22
|
+
if (!activeSidebarItem) return
|
|
23
|
+
|
|
24
|
+
// get the top and height of the sidebar
|
|
25
|
+
const { top: sidebarTop, height: sidebarHeight } =
|
|
26
|
+
sidebar.getBoundingClientRect()
|
|
27
|
+
// get the top and height of the active sidebar item
|
|
28
|
+
const { top: activeSidebarItemTop, height: activeSidebarItemHeight } =
|
|
29
|
+
activeSidebarItem.getBoundingClientRect()
|
|
30
|
+
|
|
31
|
+
// when the active sidebar item overflows the top edge of sidebar
|
|
32
|
+
if (activeSidebarItemTop < sidebarTop) {
|
|
33
|
+
// scroll to the top edge of sidebar
|
|
34
|
+
activeSidebarItem.scrollIntoView(true)
|
|
35
|
+
}
|
|
36
|
+
// when the active sidebar item overflows the bottom edge of sidebar
|
|
37
|
+
else if (
|
|
38
|
+
activeSidebarItemTop + activeSidebarItemHeight >
|
|
39
|
+
sidebarTop + sidebarHeight
|
|
40
|
+
) {
|
|
41
|
+
// scroll to the bottom edge of sidebar
|
|
42
|
+
activeSidebarItem.scrollIntoView(false)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<template>
|
|
50
|
+
<ul v-if="sidebarItems.length" class="sidebar-items">
|
|
51
|
+
<SidebarItem
|
|
52
|
+
v-for="item in sidebarItems"
|
|
53
|
+
:key="`${item.text}${item.link}`"
|
|
54
|
+
:item="item"
|
|
55
|
+
/>
|
|
56
|
+
</ul>
|
|
57
|
+
</template>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useDarkMode, useThemeLocaleData } from '../composables/index.js'
|
|
3
|
+
|
|
4
|
+
const themeLocale = useThemeLocaleData()
|
|
5
|
+
const isDarkMode = useDarkMode()
|
|
6
|
+
|
|
7
|
+
const toggleColorMode = (): void => {
|
|
8
|
+
isDarkMode.value = !isDarkMode.value
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<button
|
|
14
|
+
class="toggle-color-mode-button"
|
|
15
|
+
:title="themeLocale.toggleColorMode"
|
|
16
|
+
@click="toggleColorMode"
|
|
17
|
+
>
|
|
18
|
+
<svg
|
|
19
|
+
v-show="!isDarkMode"
|
|
20
|
+
class="icon"
|
|
21
|
+
focusable="false"
|
|
22
|
+
viewBox="0 0 32 32"
|
|
23
|
+
>
|
|
24
|
+
<path
|
|
25
|
+
d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z"
|
|
26
|
+
fill="currentColor"
|
|
27
|
+
/>
|
|
28
|
+
<path
|
|
29
|
+
d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z"
|
|
30
|
+
fill="currentColor"
|
|
31
|
+
/>
|
|
32
|
+
<path d="M2 15.005h5v2H2z" fill="currentColor" />
|
|
33
|
+
<path
|
|
34
|
+
d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z"
|
|
35
|
+
fill="currentColor"
|
|
36
|
+
/>
|
|
37
|
+
<path d="M15 25.005h2v5h-2z" fill="currentColor" />
|
|
38
|
+
<path
|
|
39
|
+
d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z"
|
|
40
|
+
fill="currentColor"
|
|
41
|
+
/>
|
|
42
|
+
<path d="M25 15.005h5v2h-5z" fill="currentColor" />
|
|
43
|
+
<path
|
|
44
|
+
d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z"
|
|
45
|
+
fill="currentColor"
|
|
46
|
+
/>
|
|
47
|
+
<path d="M15 2.005h2v5h-2z" fill="currentColor" />
|
|
48
|
+
</svg>
|
|
49
|
+
|
|
50
|
+
<svg v-show="isDarkMode" class="icon" focusable="false" viewBox="0 0 32 32">
|
|
51
|
+
<path
|
|
52
|
+
d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z"
|
|
53
|
+
fill="currentColor"
|
|
54
|
+
/>
|
|
55
|
+
</svg>
|
|
56
|
+
</button>
|
|
57
|
+
</template>
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
<svg
|
|
4
|
-
class="icon"
|
|
5
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
6
|
-
aria-hidden="true"
|
|
7
|
-
role="img"
|
|
8
|
-
viewBox="0 0 448 512"
|
|
9
|
-
>
|
|
10
|
-
<path
|
|
11
|
-
fill="currentColor"
|
|
12
|
-
d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"
|
|
13
|
-
class=""
|
|
14
|
-
/>
|
|
15
|
-
</svg>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script lang="ts">
|
|
20
|
-
import { defineComponent } from 'vue'
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useThemeLocaleData } from '../composables/index.js'
|
|
21
3
|
|
|
22
|
-
|
|
23
|
-
name: 'ToggleSidebarButton',
|
|
4
|
+
defineEmits<(e: 'toggle') => void>()
|
|
24
5
|
|
|
25
|
-
|
|
26
|
-
})
|
|
6
|
+
const themeLocale = useThemeLocaleData()
|
|
27
7
|
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<div
|
|
11
|
+
class="toggle-sidebar-button"
|
|
12
|
+
:title="themeLocale.toggleSidebar"
|
|
13
|
+
aria-expanded="false"
|
|
14
|
+
role="button"
|
|
15
|
+
tabindex="0"
|
|
16
|
+
@click="$emit('toggle')"
|
|
17
|
+
>
|
|
18
|
+
<div class="icon" aria-hidden="true">
|
|
19
|
+
<span></span>
|
|
20
|
+
<span></span>
|
|
21
|
+
<span></span>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
type: {
|
|
4
|
+
type: String,
|
|
5
|
+
required: false,
|
|
6
|
+
default: 'tip',
|
|
7
|
+
},
|
|
8
|
+
text: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: false,
|
|
11
|
+
default: '',
|
|
12
|
+
},
|
|
13
|
+
vertical: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: false,
|
|
16
|
+
default: undefined,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
defineSlots<{
|
|
21
|
+
default?: () => any
|
|
22
|
+
}>()
|
|
23
|
+
</script>
|
|
24
|
+
|
|
1
25
|
<template>
|
|
2
26
|
<span
|
|
3
27
|
class="badge"
|
|
@@ -9,29 +33,3 @@
|
|
|
9
33
|
<slot>{{ text }}</slot>
|
|
10
34
|
</span>
|
|
11
35
|
</template>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
import { defineComponent } from 'vue'
|
|
15
|
-
|
|
16
|
-
export default defineComponent({
|
|
17
|
-
name: 'Badge',
|
|
18
|
-
|
|
19
|
-
props: {
|
|
20
|
-
type: {
|
|
21
|
-
type: String,
|
|
22
|
-
required: false,
|
|
23
|
-
default: 'tip',
|
|
24
|
-
},
|
|
25
|
-
text: {
|
|
26
|
-
type: String,
|
|
27
|
-
required: false,
|
|
28
|
-
default: '',
|
|
29
|
-
},
|
|
30
|
-
vertical: {
|
|
31
|
-
type: String,
|
|
32
|
-
required: false,
|
|
33
|
-
default: undefined,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
</script>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { VNode } from 'vue';
|
|
2
|
-
declare const
|
|
1
|
+
import type { SlotsType, VNode } from 'vue';
|
|
2
|
+
export declare const CodeGroup: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
3
3
|
[key: string]: any;
|
|
4
|
-
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin,
|
|
5
|
-
|
|
4
|
+
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, SlotsType<{
|
|
5
|
+
default: () => VNode[];
|
|
6
|
+
}>>;
|
|
@@ -1,16 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { useStorage } from '@vueuse/core';
|
|
2
|
+
import { computed, defineComponent, h, onBeforeUpdate, onMounted, ref, watch, } from 'vue';
|
|
3
|
+
export const CodeGroup = defineComponent({
|
|
3
4
|
name: 'CodeGroup',
|
|
5
|
+
slots: Object,
|
|
4
6
|
setup(_, { slots }) {
|
|
7
|
+
// refs of the tab buttons
|
|
8
|
+
const tabRefs = ref([]);
|
|
9
|
+
if (__VUEPRESS_DEV__) {
|
|
10
|
+
// in dev mode, we need to clear the tabs ref to avoid HMR issues
|
|
11
|
+
// after removing a code-group-item
|
|
12
|
+
onBeforeUpdate(() => {
|
|
13
|
+
tabRefs.value = [];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
5
16
|
// index of current active item
|
|
6
17
|
const activeIndex = ref(-1);
|
|
18
|
+
const codeGroupStorage = useStorage('vuepress-code-group', {});
|
|
19
|
+
const codeGroupKey = computed(() => tabRefs.value.map((tab) => tab.innerText).join(','));
|
|
20
|
+
onMounted(() => {
|
|
21
|
+
watch(() => codeGroupStorage.value[codeGroupKey.value], (val = -1) => {
|
|
22
|
+
if (activeIndex.value !== val) {
|
|
23
|
+
activeIndex.value = val;
|
|
24
|
+
}
|
|
25
|
+
}, { immediate: true });
|
|
26
|
+
watch(activeIndex, (val) => {
|
|
27
|
+
if (codeGroupStorage.value[codeGroupKey.value] !== val) {
|
|
28
|
+
codeGroupStorage.value[codeGroupKey.value] = val;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
// activate next tab
|
|
33
|
+
const activateNext = (i = activeIndex.value) => {
|
|
34
|
+
if (i < tabRefs.value.length - 1) {
|
|
35
|
+
activeIndex.value = i + 1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
activeIndex.value = 0;
|
|
39
|
+
}
|
|
40
|
+
tabRefs.value[activeIndex.value].focus();
|
|
41
|
+
};
|
|
42
|
+
// activate previous tab
|
|
43
|
+
const activatePrev = (i = activeIndex.value) => {
|
|
44
|
+
if (i > 0) {
|
|
45
|
+
activeIndex.value = i - 1;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
activeIndex.value = tabRefs.value.length - 1;
|
|
49
|
+
}
|
|
50
|
+
tabRefs.value[activeIndex.value].focus();
|
|
51
|
+
};
|
|
52
|
+
// handle keyboard event
|
|
53
|
+
const keyboardHandler = (event, i) => {
|
|
54
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
activeIndex.value = i;
|
|
57
|
+
}
|
|
58
|
+
else if (event.key === 'ArrowRight') {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
activateNext(i);
|
|
61
|
+
}
|
|
62
|
+
else if (event.key === 'ArrowLeft') {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
activatePrev(i);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
7
67
|
return () => {
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
// `setup()` function of current component is called
|
|
11
|
-
var _a;
|
|
12
|
-
// get children code-group-item
|
|
13
|
-
const items = (((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) || [])
|
|
68
|
+
// get children code-group-item from default slots
|
|
69
|
+
const items = (slots.default?.() || [])
|
|
14
70
|
.filter((vnode) => vnode.type.name === 'CodeGroupItem')
|
|
15
71
|
.map((vnode) => {
|
|
16
72
|
if (vnode.props === null) {
|
|
@@ -22,8 +78,8 @@ export default defineComponent({
|
|
|
22
78
|
if (items.length === 0) {
|
|
23
79
|
return null;
|
|
24
80
|
}
|
|
25
|
-
if
|
|
26
|
-
|
|
81
|
+
// if activeIndex is invalid
|
|
82
|
+
if (activeIndex.value < 0 || activeIndex.value > items.length - 1) {
|
|
27
83
|
// find the index of the code-group-item with `active` props
|
|
28
84
|
activeIndex.value = items.findIndex((vnode) => vnode.props.active === '' || vnode.props.active === true);
|
|
29
85
|
// if there is no `active` props on code-group-item, set the first item active
|
|
@@ -31,20 +87,32 @@ export default defineComponent({
|
|
|
31
87
|
activeIndex.value = 0;
|
|
32
88
|
}
|
|
33
89
|
}
|
|
90
|
+
// if activeIndex is valid
|
|
34
91
|
else {
|
|
35
|
-
// re-render triggered by modifying `activeIndex` ref
|
|
36
92
|
// set the active item
|
|
37
93
|
items.forEach((vnode, i) => {
|
|
38
94
|
vnode.props.active = i === activeIndex.value;
|
|
39
95
|
});
|
|
40
96
|
}
|
|
41
97
|
return h('div', { class: 'code-group' }, [
|
|
42
|
-
h('div', { class: 'code-group__nav' }, h('ul', { class: 'code-group__ul' }, items.map((vnode, i) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
:
|
|
46
|
-
|
|
47
|
-
|
|
98
|
+
h('div', { class: 'code-group__nav' }, h('ul', { class: 'code-group__ul' }, items.map((vnode, i) => {
|
|
99
|
+
const isActive = i === activeIndex.value;
|
|
100
|
+
return h('li', { class: 'code-group__li' }, h('button', {
|
|
101
|
+
ref: (element) => {
|
|
102
|
+
if (element) {
|
|
103
|
+
tabRefs.value[i] = element;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
class: {
|
|
107
|
+
'code-group__nav-tab': true,
|
|
108
|
+
'code-group__nav-tab-active': isActive,
|
|
109
|
+
},
|
|
110
|
+
ariaPressed: isActive,
|
|
111
|
+
ariaExpanded: isActive,
|
|
112
|
+
onClick: () => (activeIndex.value = i),
|
|
113
|
+
onKeydown: (e) => keyboardHandler(e, i),
|
|
114
|
+
}, vnode.props.title));
|
|
115
|
+
}))),
|
|
48
116
|
items,
|
|
49
117
|
]);
|
|
50
118
|
};
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
<
|
|
2
|
-
<div class="code-group-item" :class="{ 'code-group-item__active': active }">
|
|
3
|
-
<slot />
|
|
4
|
-
</div>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
8
2
|
import { defineComponent } from 'vue'
|
|
9
3
|
|
|
10
4
|
export default defineComponent({
|
|
11
5
|
name: 'CodeGroupItem',
|
|
6
|
+
})
|
|
7
|
+
</script>
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
defineProps({
|
|
11
|
+
title: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
active: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
required: false,
|
|
18
|
+
default: false,
|
|
23
19
|
},
|
|
24
20
|
})
|
|
25
21
|
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<div
|
|
25
|
+
class="code-group-item"
|
|
26
|
+
:class="{ 'code-group-item__active': active }"
|
|
27
|
+
:aria-selected="active"
|
|
28
|
+
>
|
|
29
|
+
<slot />
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './useDarkMode.js';
|
|
2
|
+
export * from './useNavLink.js';
|
|
3
|
+
export * from './useResolveRouteWithRedirect.js';
|
|
4
|
+
export * from './useScrollPromise.js';
|
|
5
|
+
export * from './useSidebarItems.js';
|
|
6
|
+
export * from './useThemeData.js';
|
|
7
|
+
export * from './useUpdateDeviceStatus.js';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './useDarkMode.js';
|
|
2
|
+
export * from './useNavLink.js';
|
|
3
|
+
export * from './useResolveRouteWithRedirect.js';
|
|
4
|
+
export * from './useScrollPromise.js';
|
|
5
|
+
export * from './useSidebarItems.js';
|
|
6
|
+
export * from './useThemeData.js';
|
|
7
|
+
export * from './useUpdateDeviceStatus.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InjectionKey, WritableComputedRef } from 'vue';
|
|
2
|
+
export type DarkModeRef = WritableComputedRef<boolean>;
|
|
3
|
+
export declare const darkModeSymbol: InjectionKey<DarkModeRef>;
|
|
4
|
+
/**
|
|
5
|
+
* Inject dark mode global computed
|
|
6
|
+
*/
|
|
7
|
+
export declare const useDarkMode: () => DarkModeRef;
|
|
8
|
+
/**
|
|
9
|
+
* Create dark mode ref and provide as global computed in setup
|
|
10
|
+
*/
|
|
11
|
+
export declare const setupDarkMode: () => void;
|
|
12
|
+
export declare const updateHtmlDarkClass: (isDarkMode: DarkModeRef) => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { usePreferredDark, useStorage } from '@vueuse/core';
|
|
2
|
+
import { computed, inject, onMounted, onUnmounted, provide, watch } from 'vue';
|
|
3
|
+
import { useThemeLocaleData } from './useThemeData.js';
|
|
4
|
+
export const darkModeSymbol = Symbol(__VUEPRESS_DEV__ ? 'darkMode' : '');
|
|
5
|
+
/**
|
|
6
|
+
* Inject dark mode global computed
|
|
7
|
+
*/
|
|
8
|
+
export const useDarkMode = () => {
|
|
9
|
+
const isDarkMode = inject(darkModeSymbol);
|
|
10
|
+
if (!isDarkMode) {
|
|
11
|
+
throw new Error('useDarkMode() is called without provider.');
|
|
12
|
+
}
|
|
13
|
+
return isDarkMode;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Create dark mode ref and provide as global computed in setup
|
|
17
|
+
*/
|
|
18
|
+
export const setupDarkMode = () => {
|
|
19
|
+
const themeLocale = useThemeLocaleData();
|
|
20
|
+
const isDarkPreferred = usePreferredDark();
|
|
21
|
+
const darkStorage = useStorage('vuepress-color-scheme', themeLocale.value.colorMode);
|
|
22
|
+
const isDarkMode = computed({
|
|
23
|
+
get() {
|
|
24
|
+
// disable color mode switching
|
|
25
|
+
if (!themeLocale.value.colorModeSwitch) {
|
|
26
|
+
return themeLocale.value.colorMode === 'dark';
|
|
27
|
+
}
|
|
28
|
+
// auto detected from prefers-color-scheme
|
|
29
|
+
if (darkStorage.value === 'auto') {
|
|
30
|
+
return isDarkPreferred.value;
|
|
31
|
+
}
|
|
32
|
+
// storage value
|
|
33
|
+
return darkStorage.value === 'dark';
|
|
34
|
+
},
|
|
35
|
+
set(val) {
|
|
36
|
+
if (val === isDarkPreferred.value) {
|
|
37
|
+
darkStorage.value = 'auto';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
darkStorage.value = val ? 'dark' : 'light';
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
provide(darkModeSymbol, isDarkMode);
|
|
45
|
+
updateHtmlDarkClass(isDarkMode);
|
|
46
|
+
};
|
|
47
|
+
export const updateHtmlDarkClass = (isDarkMode) => {
|
|
48
|
+
const update = (value = isDarkMode.value) => {
|
|
49
|
+
// set `class="dark"` on `<html>` element
|
|
50
|
+
const htmlEl = window?.document.querySelector('html');
|
|
51
|
+
htmlEl?.classList.toggle('dark', value);
|
|
52
|
+
};
|
|
53
|
+
onMounted(() => {
|
|
54
|
+
watch(isDarkMode, update, { immediate: true });
|
|
55
|
+
});
|
|
56
|
+
onUnmounted(() => update());
|
|
57
|
+
};
|