@vuepress/theme-default 2.0.0-rc.9 → 2.0.0-rc.90

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.
Files changed (145) hide show
  1. package/lib/client/components/VPAutoLink.vue +32 -0
  2. package/lib/client/components/VPDarkIcon.vue +8 -0
  3. package/lib/client/components/VPDropdownTransition.vue +43 -0
  4. package/lib/client/components/VPEditIcon.vue +12 -0
  5. package/lib/client/components/VPFadeSlideYTransition.vue +43 -0
  6. package/lib/client/components/VPHome.vue +37 -0
  7. package/lib/client/components/VPHomeFeatures.vue +65 -0
  8. package/lib/client/components/{HomeFooter.vue → VPHomeFooter.vue} +16 -3
  9. package/lib/client/components/VPHomeHero.vue +185 -0
  10. package/lib/client/components/VPLightIcon.vue +28 -0
  11. package/lib/client/components/VPNavbar.vue +134 -0
  12. package/lib/client/components/{NavbarBrand.vue → VPNavbarBrand.vue} +41 -16
  13. package/lib/client/components/VPNavbarDropdown.vue +328 -0
  14. package/lib/client/components/VPNavbarItems.vue +111 -0
  15. package/lib/client/components/VPPage.vue +69 -0
  16. package/lib/client/components/VPPageMeta.vue +139 -0
  17. package/lib/client/components/VPPageNav.vue +123 -0
  18. package/lib/client/components/VPSidebar.vue +120 -0
  19. package/lib/client/components/VPSidebarItem.vue +189 -0
  20. package/lib/client/components/{SidebarItems.vue → VPSidebarItems.vue} +27 -7
  21. package/lib/client/components/VPToggleColorModeButton.vue +55 -0
  22. package/lib/client/components/VPToggleSidebarButton.vue +92 -0
  23. package/lib/client/components/global/Badge.vue +84 -18
  24. package/lib/client/components/global/index.d.ts +1 -3
  25. package/lib/client/components/global/index.js +1 -3
  26. package/lib/client/composables/index.d.ts +7 -1
  27. package/lib/client/composables/index.js +7 -1
  28. package/lib/client/composables/useDarkMode.d.ts +0 -1
  29. package/lib/client/composables/useDarkMode.js +19 -16
  30. package/lib/client/composables/useData.d.ts +13 -0
  31. package/lib/client/composables/useData.js +15 -0
  32. package/lib/client/composables/useEditLink.d.ts +3 -0
  33. package/lib/client/composables/useEditLink.js +28 -0
  34. package/lib/client/composables/useHeaders.d.ts +9 -0
  35. package/lib/client/composables/useHeaders.js +38 -0
  36. package/lib/client/composables/useNavbarConfig.d.ts +3 -0
  37. package/lib/client/composables/useNavbarConfig.js +29 -0
  38. package/lib/client/composables/useNavbarRepo.d.ts +6 -0
  39. package/lib/client/composables/useNavbarRepo.js +38 -0
  40. package/lib/client/composables/useNavbarSelectLanguage.d.ts +6 -0
  41. package/lib/client/composables/useNavbarSelectLanguage.js +55 -0
  42. package/lib/client/composables/useNavigate.d.ts +1 -0
  43. package/lib/client/composables/useNavigate.js +22 -0
  44. package/lib/client/composables/useRelatedLinks.d.ts +8 -0
  45. package/lib/client/composables/useRelatedLinks.js +90 -0
  46. package/lib/client/composables/useScrollPromise.js +3 -1
  47. package/lib/client/composables/useSidebarItems.d.ts +21 -21
  48. package/lib/client/composables/useSidebarItems.js +96 -86
  49. package/lib/client/composables/useUpdateDeviceStatus.d.ts +1 -1
  50. package/lib/client/composables/useUpdateDeviceStatus.js +10 -5
  51. package/lib/client/config.d.ts +3 -2
  52. package/lib/client/config.js +8 -23
  53. package/lib/client/index.d.ts +2 -1
  54. package/lib/client/index.js +0 -1
  55. package/lib/client/layouts/Layout.vue +128 -56
  56. package/lib/client/layouts/NotFound.vue +25 -11
  57. package/lib/client/shim.d.ts +6 -5
  58. package/lib/client/styles/_mixins.scss +4 -4
  59. package/lib/client/styles/_variables.module.scss +1 -1
  60. package/lib/client/styles/_variables.scss +2 -1
  61. package/lib/client/styles/arrow.scss +24 -22
  62. package/lib/client/styles/code-group.scss +34 -30
  63. package/lib/client/styles/content/code.scss +23 -0
  64. package/lib/client/styles/content/index.scss +3 -0
  65. package/lib/client/styles/content/normalize.scss +39 -0
  66. package/lib/client/styles/{toc.scss → content/toc.scss} +1 -1
  67. package/lib/client/styles/external-link-icon.scss +36 -0
  68. package/lib/client/styles/index.scss +3 -13
  69. package/lib/client/styles/layout.scss +5 -197
  70. package/lib/client/styles/normalize.scss +1 -194
  71. package/lib/client/styles/plugins.scss +28 -0
  72. package/lib/client/styles/vars-dark.scss +20 -58
  73. package/lib/client/styles/vars.scss +54 -130
  74. package/lib/client/typings.d.ts +13 -0
  75. package/lib/client/typings.js +1 -0
  76. package/lib/client/utils/index.d.ts +2 -2
  77. package/lib/client/utils/index.js +2 -2
  78. package/lib/client/utils/isActiveSidebarItem.d.ts +3 -3
  79. package/lib/client/utils/isActiveSidebarItem.js +1 -1
  80. package/lib/client/utils/resolveAutoLink.d.ts +9 -0
  81. package/lib/client/utils/resolveAutoLink.js +17 -0
  82. package/lib/client/utils/resolveEditLink.d.ts +3 -3
  83. package/lib/client/utils/resolveEditLink.js +3 -3
  84. package/lib/client/utils/resolvePrefix.d.ts +1 -0
  85. package/lib/client/utils/resolvePrefix.js +4 -0
  86. package/lib/client/utils/resolveRepoType.d.ts +1 -1
  87. package/lib/client/utils/resolveRepoType.js +4 -4
  88. package/lib/node/defaultTheme.d.ts +2 -1
  89. package/lib/node/defaultTheme.js +57 -64
  90. package/lib/node/index.d.ts +2 -3
  91. package/lib/node/index.js +0 -3
  92. package/lib/node/typings.d.ts +59 -0
  93. package/lib/node/typings.js +1 -0
  94. package/lib/node/utils/assignDefaultLocaleOptions.js +3 -8
  95. package/lib/node/utils/index.d.ts +1 -1
  96. package/lib/node/utils/index.js +1 -1
  97. package/lib/node/utils/resolveMarkdownHintLocales.d.ts +9 -0
  98. package/lib/node/utils/resolveMarkdownHintLocales.js +19 -0
  99. package/lib/shared/index.d.ts +5 -3
  100. package/lib/shared/index.js +1 -3
  101. package/lib/shared/nav.d.ts +19 -30
  102. package/lib/shared/navbar.d.ts +21 -0
  103. package/lib/shared/navbar.js +1 -0
  104. package/lib/shared/options.d.ts +36 -66
  105. package/lib/shared/page.d.ts +9 -6
  106. package/lib/shared/sidebar.d.ts +26 -0
  107. package/lib/shared/sidebar.js +1 -0
  108. package/package.json +29 -27
  109. package/templates/build.html +16 -10
  110. package/lib/client/components/AutoLink.vue +0 -113
  111. package/lib/client/components/DropdownTransition.vue +0 -25
  112. package/lib/client/components/Home.vue +0 -15
  113. package/lib/client/components/HomeContent.vue +0 -5
  114. package/lib/client/components/HomeFeatures.vue +0 -22
  115. package/lib/client/components/HomeHero.vue +0 -97
  116. package/lib/client/components/Navbar.vue +0 -79
  117. package/lib/client/components/NavbarDropdown.vue +0 -126
  118. package/lib/client/components/NavbarItems.vue +0 -199
  119. package/lib/client/components/Page.vue +0 -31
  120. package/lib/client/components/PageMeta.vue +0 -124
  121. package/lib/client/components/PageNav.vue +0 -122
  122. package/lib/client/components/Sidebar.vue +0 -18
  123. package/lib/client/components/SidebarItem.vue +0 -87
  124. package/lib/client/components/ToggleColorModeButton.vue +0 -57
  125. package/lib/client/components/ToggleSidebarButton.vue +0 -24
  126. package/lib/client/components/global/CodeGroup.d.ts +0 -6
  127. package/lib/client/components/global/CodeGroup.js +0 -120
  128. package/lib/client/components/global/CodeGroupItem.vue +0 -27
  129. package/lib/client/composables/useThemeData.d.ts +0 -4
  130. package/lib/client/composables/useThemeData.js +0 -3
  131. package/lib/client/styles/badge.scss +0 -36
  132. package/lib/client/styles/code.scss +0 -263
  133. package/lib/client/styles/custom-container.scss +0 -142
  134. package/lib/client/styles/home.scss +0 -168
  135. package/lib/client/styles/navbar-dropdown.scss +0 -183
  136. package/lib/client/styles/navbar.scss +0 -197
  137. package/lib/client/styles/page.scss +0 -87
  138. package/lib/client/styles/sidebar.scss +0 -134
  139. package/lib/client/styles/transitions.scss +0 -22
  140. package/lib/client/utils/getNavLink.d.ts +0 -15
  141. package/lib/client/utils/getNavLink.js +0 -18
  142. package/lib/client/utils/getResolveRouteWithRedirect.d.ts +0 -5
  143. package/lib/client/utils/getResolveRouteWithRedirect.js +0 -22
  144. package/lib/node/utils/resolveContainerPluginOptions.d.ts +0 -8
  145. package/lib/node/utils/resolveContainerPluginOptions.js +0 -17
@@ -0,0 +1,90 @@
1
+ import { resolveAutoLink } from '@theme/resolveAutoLink';
2
+ import { useData } from '@theme/useData';
3
+ import { useSidebarItems } from '@theme/useSidebarItems';
4
+ import { computed } from 'vue';
5
+ import { resolveRoute, useRoutePath } from 'vuepress/client';
6
+ import { isPlainObject, isString } from 'vuepress/shared';
7
+ const resolveFromFrontmatterConfig = (config, currentPath) => {
8
+ if (config === false) {
9
+ return false;
10
+ }
11
+ if (isString(config)) {
12
+ return resolveAutoLink(config, currentPath);
13
+ }
14
+ if (isPlainObject(config)) {
15
+ return {
16
+ ...config,
17
+ link: resolveAutoLink(config.link, currentPath).link,
18
+ };
19
+ }
20
+ return null;
21
+ };
22
+ /**
23
+ * Resolve `prev` or `next` config from sidebar items
24
+ */
25
+ const resolveFromSidebarItems = (sidebarItems, currentPath, offset) => {
26
+ const linkIndex = sidebarItems.findIndex((item) => item.link === currentPath);
27
+ if (linkIndex !== -1) {
28
+ const targetItem = sidebarItems[linkIndex + offset];
29
+ if (!targetItem)
30
+ return null;
31
+ if (targetItem.link)
32
+ return targetItem;
33
+ if ('prefix' in targetItem && !resolveRoute(targetItem.prefix).notFound)
34
+ return {
35
+ ...targetItem,
36
+ link: targetItem.prefix,
37
+ };
38
+ return null;
39
+ }
40
+ for (const item of sidebarItems) {
41
+ if ('children' in item) {
42
+ const childResult = resolveFromSidebarItems(item.children, currentPath, offset);
43
+ if (childResult) {
44
+ return childResult;
45
+ }
46
+ }
47
+ }
48
+ const prefixIndex = sidebarItems.findIndex((item) => 'prefix' in item && item.prefix === currentPath);
49
+ if (prefixIndex !== -1) {
50
+ const targetItem = sidebarItems[prefixIndex + offset];
51
+ if (!targetItem)
52
+ return null;
53
+ if (targetItem.link)
54
+ return targetItem;
55
+ if ('prefix' in targetItem && !resolveRoute(targetItem.prefix).notFound)
56
+ return {
57
+ ...targetItem,
58
+ link: targetItem.prefix,
59
+ };
60
+ return null;
61
+ }
62
+ return null;
63
+ };
64
+ export const useRelatedLinks = () => {
65
+ const { frontmatter, themeLocale } = useData();
66
+ const sidebarItems = useSidebarItems();
67
+ const routePath = useRoutePath();
68
+ const prevLink = computed(() => {
69
+ const prevConfig = resolveFromFrontmatterConfig(frontmatter.value.prev, routePath.value);
70
+ return prevConfig === false
71
+ ? null
72
+ : (prevConfig ??
73
+ (themeLocale.value.prev === false
74
+ ? null
75
+ : resolveFromSidebarItems(sidebarItems.value, routePath.value, -1)));
76
+ });
77
+ const nextLink = computed(() => {
78
+ const nextConfig = resolveFromFrontmatterConfig(frontmatter.value.next, routePath.value);
79
+ return nextConfig === false
80
+ ? null
81
+ : (nextConfig ??
82
+ (themeLocale.value.next === false
83
+ ? null
84
+ : resolveFromSidebarItems(sidebarItems.value, routePath.value, 1)));
85
+ });
86
+ return {
87
+ prevLink,
88
+ nextLink,
89
+ };
90
+ };
@@ -3,7 +3,9 @@ let promiseResolve = null;
3
3
  const scrollPromise = {
4
4
  wait: () => promise,
5
5
  pending: () => {
6
- promise = new Promise((resolve) => (promiseResolve = resolve));
6
+ promise = new Promise((resolve) => {
7
+ promiseResolve = resolve;
8
+ });
7
9
  },
8
10
  resolve: () => {
9
11
  promiseResolve?.();
@@ -1,37 +1,37 @@
1
1
  import type { ComputedRef, InjectionKey } from 'vue';
2
- import type { Router } from 'vue-router';
3
2
  import type { PageData, PageHeader } from 'vuepress/client';
4
- import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
5
- export type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
6
- export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
3
+ import type { SidebarArrayOptions, SidebarObjectOptions, SidebarOptions } from '../../shared/index.js';
4
+ import type { SidebarHeaderItem, SidebarItem } from '../typings.js';
7
5
  /**
8
- * Inject sidebar items global computed
6
+ * Util to transform page header to sidebar item
9
7
  */
10
- export declare const useSidebarItems: () => SidebarItemsRef;
8
+ export declare const resolveSidebarPageHeader: (header: PageHeader) => SidebarHeaderItem;
9
+ export declare const resolveSidebarPageHeaders: (headers?: PageHeader[]) => SidebarHeaderItem[];
11
10
  /**
12
- * Create sidebar items ref and provide as global computed in setup
11
+ * Resolve current page and its header to sidebar items if the config is `heading`
13
12
  */
14
- export declare const setupSidebarItems: () => void;
13
+ export declare const resolveSidebarHeadingItem: (page: PageData, headers: PageHeader[]) => SidebarItem[];
15
14
  /**
16
- * Resolve sidebar items global computed
17
- *
18
- * It should only be resolved and provided once
15
+ * Resolve sidebar items if the config is an array
19
16
  */
20
- export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData, page: PageData, router: Router, path: string) => ResolvedSidebarItem[];
17
+ export declare const resolveArraySidebarItems: (sidebarConfig: SidebarArrayOptions, headers: PageHeader[], path: string, prefix?: string) => SidebarItem[];
21
18
  /**
22
- * Util to transform page header to sidebar item
19
+ * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
23
20
  */
24
- export declare const headerToSidebarItem: (header: PageHeader, sidebarDepth: number) => ResolvedSidebarItem;
25
- export declare const headersToSidebarItemChildren: (headers: PageHeader[], sidebarDepth: number) => ResolvedSidebarItem[];
21
+ export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarObjectOptions, page: PageData, headers: PageHeader[], path: string) => SidebarItem[];
22
+ export type SidebarItemsRef = ComputedRef<SidebarItem[]>;
23
+ export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
26
24
  /**
27
- * Resolve sidebar items if the config is `auto`
25
+ * Inject sidebar items global computed
28
26
  */
29
- export declare const resolveAutoSidebarItems: (page: PageData, sidebarDepth: number) => ResolvedSidebarItem[];
27
+ export declare const useSidebarItems: () => SidebarItemsRef;
30
28
  /**
31
- * Resolve sidebar items if the config is an array
29
+ * Resolve sidebar items global computed
30
+ *
31
+ * It should only be resolved and provided once
32
32
  */
33
- export declare const resolveArraySidebarItems: (page: PageData, router: Router, path: string, sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
33
+ export declare const resolveSidebarItems: (sidebarConfig: SidebarOptions | false, page: PageData, path: string, routeLocale: string, headers: PageHeader[]) => SidebarItem[];
34
34
  /**
35
- * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
35
+ * Create sidebar items ref and provide as global computed in setup
36
36
  */
37
- export declare const resolveMultiSidebarItems: (page: PageData, router: Router, path: string, sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
37
+ export declare const setupSidebarItems: () => void;
@@ -1,118 +1,128 @@
1
+ import { resolveAutoLink } from '@theme/resolveAutoLink';
2
+ import { resolvePrefix } from '@theme/resolvePrefix';
3
+ import { useData } from '@theme/useData';
4
+ import { useHeaders } from '@theme/useHeaders';
5
+ import { isLinkRelative, keys, startsWith } from '@vuepress/helper/client';
1
6
  import { computed, inject, provide } from 'vue';
2
- import { useRoute, useRouter } from 'vue-router';
3
- import { usePageData, usePageFrontmatter } from 'vuepress/client';
4
- import { isPlainObject, isString, resolveLocalePath } from 'vuepress/shared';
5
- import { getNavLink } from '../utils/index.js';
6
- import { useThemeLocaleData } from './useThemeData.js';
7
- export const sidebarItemsSymbol = Symbol('sidebarItems');
8
- /**
9
- * Inject sidebar items global computed
10
- */
11
- export const useSidebarItems = () => {
12
- const sidebarItems = inject(sidebarItemsSymbol);
13
- if (!sidebarItems) {
14
- throw new Error('useSidebarItems() is called without provider.');
15
- }
16
- return sidebarItems;
17
- };
18
- /**
19
- * Create sidebar items ref and provide as global computed in setup
20
- */
21
- export const setupSidebarItems = () => {
22
- const themeLocale = useThemeLocaleData();
23
- const frontmatter = usePageFrontmatter();
24
- const page = usePageData();
25
- const route = useRoute();
26
- const router = useRouter();
27
- const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value, page.value, router, route.path));
28
- provide(sidebarItemsSymbol, sidebarItems);
29
- };
30
- /**
31
- * Resolve sidebar items global computed
32
- *
33
- * It should only be resolved and provided once
34
- */
35
- export const resolveSidebarItems = (frontmatter, themeLocale, page, router, path) => {
36
- // get sidebar config from frontmatter > theme data
37
- const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
38
- const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
39
- // resolve sidebar items according to the config
40
- if (frontmatter.home || sidebarConfig === false) {
41
- return [];
42
- }
43
- if (sidebarConfig === 'auto') {
44
- return resolveAutoSidebarItems(page, sidebarDepth);
45
- }
46
- if (Array.isArray(sidebarConfig)) {
47
- return resolveArraySidebarItems(page, router, path, sidebarConfig, sidebarDepth);
48
- }
49
- if (isPlainObject(sidebarConfig)) {
50
- return resolveMultiSidebarItems(page, router, path, sidebarConfig, sidebarDepth);
51
- }
52
- return [];
53
- };
7
+ import { useRoutePath } from 'vuepress/client';
8
+ import { isPlainObject, isString } from 'vuepress/shared';
54
9
  /**
55
10
  * Util to transform page header to sidebar item
56
11
  */
57
- export const headerToSidebarItem = (header, sidebarDepth) => ({
12
+ export const resolveSidebarPageHeader = (header) => ({
58
13
  text: header.title,
59
14
  link: header.link,
60
- children: headersToSidebarItemChildren(header.children, sidebarDepth),
15
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
16
+ children: resolveSidebarPageHeaders(header.children),
61
17
  });
62
- export const headersToSidebarItemChildren = (headers, sidebarDepth) => sidebarDepth > 0
63
- ? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
64
- : [];
18
+ export const resolveSidebarPageHeaders = (headers) => headers ? headers.map((header) => resolveSidebarPageHeader(header)) : [];
65
19
  /**
66
- * Resolve sidebar items if the config is `auto`
20
+ * Resolve current page and its header to sidebar items if the config is `heading`
67
21
  */
68
- export const resolveAutoSidebarItems = (page, sidebarDepth) => {
69
- return [
70
- {
71
- text: page.title,
72
- children: headersToSidebarItemChildren(page.headers, sidebarDepth),
73
- },
74
- ];
75
- };
22
+ export const resolveSidebarHeadingItem = (page, headers) => [
23
+ {
24
+ text: page.title,
25
+ children: resolveSidebarPageHeaders(headers),
26
+ },
27
+ ];
76
28
  /**
77
29
  * Resolve sidebar items if the config is an array
78
30
  */
79
- export const resolveArraySidebarItems = (page, router, path, sidebarConfig, sidebarDepth) => {
80
- const handleChildItem = (item) => {
81
- let childItem;
82
- if (isString(item)) {
83
- childItem = getNavLink(router, item);
84
- }
85
- else {
86
- childItem = item;
87
- }
88
- if (childItem.children) {
31
+ export const resolveArraySidebarItems = (sidebarConfig, headers, path, prefix = '') => {
32
+ const handleChildItem = (item, pathPrefix) => {
33
+ const childItem = isString(item)
34
+ ? resolveAutoLink(resolvePrefix(pathPrefix, item))
35
+ : isString(item.link)
36
+ ? {
37
+ ...item,
38
+ link: isLinkRelative(item.link)
39
+ ? resolveAutoLink(resolvePrefix(pathPrefix, item.link)).link
40
+ : item.link,
41
+ }
42
+ : item;
43
+ if ('children' in childItem) {
89
44
  return {
90
45
  ...childItem,
91
- children: childItem.children.map((item) => handleChildItem(item)),
46
+ children: childItem.children.map((child) => handleChildItem(child, resolvePrefix(pathPrefix, childItem.prefix))),
92
47
  };
93
48
  }
94
49
  // if the sidebar item is current page and children is not set
95
50
  // use headers of current page as children
96
51
  if (childItem.link === path) {
97
52
  // skip h1 header
98
- const headers = page.headers[0]?.level === 1 ? page.headers[0].children : page.headers;
53
+ const currentHeaders = headers[0]?.level === 1 ? headers[0].children : headers;
99
54
  return {
100
55
  ...childItem,
101
- children: headersToSidebarItemChildren(headers, sidebarDepth),
56
+ children: resolveSidebarPageHeaders(currentHeaders),
102
57
  };
103
58
  }
104
59
  return childItem;
105
60
  };
106
- return sidebarConfig.map((item) => handleChildItem(item));
61
+ return sidebarConfig.map((item) => handleChildItem(item, prefix));
107
62
  };
108
63
  /**
109
64
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
110
65
  */
111
- export const resolveMultiSidebarItems = (page, router, path, sidebarConfig, sidebarDepth) => {
112
- const sidebarPath = resolveLocalePath(sidebarConfig, path);
113
- const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
114
- if (matchedSidebarConfig === 'heading') {
115
- return resolveAutoSidebarItems(page, sidebarDepth);
66
+ export const resolveMultiSidebarItems = (sidebarConfig, page, headers, path) => {
67
+ const sidebarRoutes = keys(sidebarConfig).sort((x, y) => y.length - x.length);
68
+ // Find matching config
69
+ for (const base of sidebarRoutes)
70
+ if (startsWith(decodeURI(path), base)) {
71
+ const matched = sidebarConfig[base];
72
+ return matched
73
+ ? matched === 'heading'
74
+ ? resolveSidebarHeadingItem(page, headers)
75
+ : resolveArraySidebarItems(matched, headers, path, base)
76
+ : [];
77
+ }
78
+ // eslint-disable-next-line no-console
79
+ console.warn(`${decodeURI(path)} is missing sidebar config.`);
80
+ return [];
81
+ };
82
+ export const sidebarItemsSymbol = Symbol('sidebarItems');
83
+ /**
84
+ * Inject sidebar items global computed
85
+ */
86
+ export const useSidebarItems = () => {
87
+ const sidebarItems = inject(sidebarItemsSymbol);
88
+ if (!sidebarItems) {
89
+ throw new Error('useSidebarItems() is called without provider.');
90
+ }
91
+ return sidebarItems;
92
+ };
93
+ /**
94
+ * Resolve sidebar items global computed
95
+ *
96
+ * It should only be resolved and provided once
97
+ */
98
+ export const resolveSidebarItems = (sidebarConfig, page, path, routeLocale, headers) => {
99
+ // resolve sidebar items according to the config
100
+ if (sidebarConfig === false) {
101
+ return [];
116
102
  }
117
- return resolveArraySidebarItems(page, router, path, matchedSidebarConfig, sidebarDepth);
103
+ if (sidebarConfig === 'heading') {
104
+ return resolveSidebarHeadingItem(page, headers);
105
+ }
106
+ if (Array.isArray(sidebarConfig)) {
107
+ return resolveArraySidebarItems(sidebarConfig, headers, path, routeLocale);
108
+ }
109
+ if (isPlainObject(sidebarConfig)) {
110
+ return resolveMultiSidebarItems(sidebarConfig, page, headers, path);
111
+ }
112
+ return [];
113
+ };
114
+ /**
115
+ * Create sidebar items ref and provide as global computed in setup
116
+ */
117
+ export const setupSidebarItems = () => {
118
+ const { frontmatter, page, routeLocale, themeLocale } = useData();
119
+ const headers = useHeaders();
120
+ const routePath = useRoutePath();
121
+ const sidebarConfig = computed(() => frontmatter.value.home
122
+ ? false
123
+ : (frontmatter.value.sidebar ??
124
+ themeLocale.value.sidebar ??
125
+ 'heading'));
126
+ const sidebarItems = computed(() => resolveSidebarItems(sidebarConfig.value, page.value, routePath.value, routeLocale.value, headers.value));
127
+ provide(sidebarItemsSymbol, sidebarItems);
118
128
  };
@@ -1,5 +1,5 @@
1
1
  export declare enum DeviceType {
2
- MOBILE = "mobile"
2
+ Mobile = "mobile"
3
3
  }
4
4
  /**
5
5
  * add listener to detect screen though device type
@@ -1,11 +1,12 @@
1
+ import { useEventListener } from '@vueuse/core';
1
2
  import { onMounted } from 'vue';
2
- import cssVars from '../styles/_variables.module.scss?module';
3
+ import cssVariables from '../styles/_variables.module.scss';
3
4
  export var DeviceType;
4
5
  (function (DeviceType) {
5
- DeviceType["MOBILE"] = "mobile";
6
+ DeviceType["Mobile"] = "mobile";
6
7
  })(DeviceType || (DeviceType = {}));
7
8
  const DeviceTypeMap = {
8
- [DeviceType.MOBILE]: Number.parseInt(cssVars.mobile?.replace('px', ''), 10),
9
+ [DeviceType.Mobile]: Number.parseInt(cssVariables.mobile.replace('px', ''), 10),
9
10
  };
10
11
  /**
11
12
  * add listener to detect screen though device type
@@ -17,9 +18,13 @@ export const useUpdateDeviceStatus = (deviceType, callback) => {
17
18
  throw new Error('device width must be a integer');
18
19
  return;
19
20
  }
21
+ useEventListener('orientationchange', () => {
22
+ callback(width);
23
+ });
24
+ useEventListener('resize', () => {
25
+ callback(width);
26
+ });
20
27
  onMounted(() => {
21
28
  callback(width);
22
- window.addEventListener('resize', () => callback(width), false);
23
- window.addEventListener('orientationchange', () => callback(width), false);
24
29
  });
25
30
  };
@@ -1,4 +1,5 @@
1
- import type { ClientConfig } from 'vuepress/client';
1
+ import '@vuepress/helper/colors.css';
2
+ import '@vuepress/helper/normalize.css';
2
3
  import './styles/index.scss';
3
- declare const _default: ClientConfig;
4
+ declare const _default: import("vuepress/client").ClientConfig;
4
5
  export default _default;
@@ -1,35 +1,19 @@
1
+ import { setupDarkMode } from '@theme/useDarkMode';
2
+ import { setupHeaders } from '@theme/useHeaders';
3
+ import { useScrollPromise } from '@theme/useScrollPromise';
4
+ import { setupSidebarItems } from '@theme/useSidebarItems';
1
5
  import { hasGlobalComponent } from '@vuepress/helper/client';
2
- import { h } from 'vue';
3
6
  import { defineClientConfig } from 'vuepress/client';
4
- import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
5
- import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
7
+ import { Badge } from './components/global/index.js';
6
8
  import Layout from './layouts/Layout.vue';
7
9
  import NotFound from './layouts/NotFound.vue';
10
+ import '@vuepress/helper/colors.css';
11
+ import '@vuepress/helper/normalize.css';
8
12
  import './styles/index.scss';
9
13
  export default defineClientConfig({
10
14
  enhance({ app, router }) {
11
15
  if (!hasGlobalComponent('Badge'))
12
16
  app.component('Badge', Badge);
13
- if (!hasGlobalComponent('CodeGroup'))
14
- app.component('CodeGroup', CodeGroup);
15
- if (!hasGlobalComponent('CodeGroupItem'))
16
- app.component('CodeGroupItem', CodeGroupItem);
17
- // compat with @vuepress/plugin-external-link-icon
18
- app.component('AutoLinkExternalIcon', () => {
19
- const ExternalLinkIcon = app.component('ExternalLinkIcon');
20
- if (ExternalLinkIcon) {
21
- return h(ExternalLinkIcon);
22
- }
23
- return null;
24
- });
25
- // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
26
- app.component('NavbarSearch', () => {
27
- const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
28
- if (SearchComponent) {
29
- return h(SearchComponent);
30
- }
31
- return null;
32
- });
33
17
  // handle scrollBehavior with transition
34
18
  const scrollBehavior = router.options.scrollBehavior;
35
19
  router.options.scrollBehavior = async (...args) => {
@@ -39,6 +23,7 @@ export default defineClientConfig({
39
23
  },
40
24
  setup() {
41
25
  setupDarkMode();
26
+ setupHeaders();
42
27
  setupSidebarItems();
43
28
  },
44
29
  layouts: {
@@ -1,3 +1,4 @@
1
- export * from '../shared/index.js';
2
1
  export * from './composables/index.js';
2
+ export type * from './typings.js';
3
3
  export * from './utils/index.js';
4
+ export type * from '../shared/index.js';
@@ -1,3 +1,2 @@
1
- export * from '../shared/index.js';
2
1
  export * from './composables/index.js';
3
2
  export * from './utils/index.js';