@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.
Files changed (113) hide show
  1. package/lib/client/components/AutoLink.vue +119 -0
  2. package/lib/client/components/DropdownTransition.vue +15 -24
  3. package/lib/client/components/Home.vue +12 -130
  4. package/lib/client/components/HomeContent.vue +5 -0
  5. package/lib/client/components/HomeFeatures.vue +23 -0
  6. package/lib/client/components/HomeFooter.vue +17 -0
  7. package/lib/client/components/HomeHero.vue +98 -0
  8. package/lib/client/components/Navbar.vue +60 -95
  9. package/lib/client/components/NavbarBrand.vue +55 -0
  10. package/lib/client/components/NavbarDropdown.vue +126 -0
  11. package/lib/client/components/{NavbarLinks.vue → NavbarItems.vue} +73 -58
  12. package/lib/client/components/Page.vue +16 -15
  13. package/lib/client/components/PageMeta.vue +51 -66
  14. package/lib/client/components/PageNav.vue +47 -60
  15. package/lib/client/components/Sidebar.vue +12 -32
  16. package/lib/client/components/SidebarItem.vue +87 -0
  17. package/lib/client/components/SidebarItems.vue +57 -0
  18. package/lib/client/components/ToggleColorModeButton.vue +57 -0
  19. package/lib/client/components/ToggleSidebarButton.vue +21 -24
  20. package/lib/client/components/global/Badge.vue +24 -26
  21. package/lib/client/components/global/CodeGroup.d.ts +5 -4
  22. package/lib/client/components/global/CodeGroup.js +85 -17
  23. package/lib/client/components/global/CodeGroupItem.vue +23 -17
  24. package/lib/client/components/global/index.d.ts +4 -0
  25. package/lib/client/components/global/index.js +4 -0
  26. package/lib/client/composables/index.d.ts +7 -5
  27. package/lib/client/composables/index.js +7 -5
  28. package/lib/client/composables/useDarkMode.d.ts +12 -0
  29. package/lib/client/composables/useDarkMode.js +57 -0
  30. package/lib/client/composables/useNavLink.d.ts +6 -1
  31. package/lib/client/composables/useNavLink.js +5 -2
  32. package/lib/client/composables/useResolveRouteWithRedirect.js +2 -2
  33. package/lib/client/composables/useScrollPromise.js +1 -1
  34. package/lib/client/composables/useSidebarItems.d.ts +13 -8
  35. package/lib/client/composables/useSidebarItems.js +42 -38
  36. package/lib/client/composables/useThemeData.d.ts +2 -2
  37. package/lib/client/composables/useThemeData.js +1 -1
  38. package/lib/client/composables/useUpdateDeviceStatus.d.ts +7 -0
  39. package/lib/client/composables/useUpdateDeviceStatus.js +25 -0
  40. package/lib/client/config.d.ts +3 -0
  41. package/lib/client/config.js +44 -0
  42. package/lib/client/index.d.ts +3 -4
  43. package/lib/client/index.js +3 -2
  44. package/lib/client/layouts/Layout.vue +133 -136
  45. package/lib/client/layouts/NotFound.vue +27 -0
  46. package/lib/client/shim.d.ts +5 -0
  47. package/lib/client/styles/{_wrapper.scss → _mixins.scss} +7 -2
  48. package/lib/client/styles/_variables.module.scss +5 -0
  49. package/lib/client/styles/_variables.scss +0 -28
  50. package/lib/client/styles/arrow.scss +4 -6
  51. package/lib/client/styles/badge.scss +14 -11
  52. package/lib/client/styles/code-group.scss +9 -2
  53. package/lib/client/styles/code.scss +35 -49
  54. package/lib/client/styles/custom-container.scss +82 -18
  55. package/lib/client/styles/home.scss +32 -24
  56. package/lib/client/styles/index.scss +4 -4
  57. package/lib/client/styles/layout.scss +82 -73
  58. package/lib/client/styles/{dropdown.scss → navbar-dropdown.scss} +36 -50
  59. package/lib/client/styles/navbar.scss +106 -50
  60. package/lib/client/styles/normalize.scss +200 -0
  61. package/lib/client/styles/page.scss +24 -8
  62. package/lib/client/styles/sidebar.scss +69 -87
  63. package/lib/client/styles/transitions.scss +13 -4
  64. package/lib/client/styles/vars-dark.scss +68 -0
  65. package/lib/client/styles/vars.scss +149 -0
  66. package/lib/client/utils/index.d.ts +3 -2
  67. package/lib/client/utils/index.js +3 -2
  68. package/lib/client/utils/isActiveSidebarItem.d.ts +3 -0
  69. package/lib/client/utils/isActiveSidebarItem.js +20 -0
  70. package/lib/client/utils/resolveEditLink.d.ts +2 -2
  71. package/lib/client/utils/resolveEditLink.js +15 -9
  72. package/lib/client/utils/resolveRepoType.d.ts +1 -1
  73. package/lib/client/utils/resolveRepoType.js +3 -1
  74. package/lib/node/defaultTheme.d.ts +4 -4
  75. package/lib/node/defaultTheme.js +111 -48
  76. package/lib/node/index.d.ts +4 -4
  77. package/lib/node/index.js +5 -17
  78. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +4 -2
  79. package/lib/node/utils/assignDefaultLocaleOptions.js +13 -13
  80. package/lib/node/utils/index.d.ts +2 -5
  81. package/lib/node/utils/index.js +2 -17
  82. package/lib/node/utils/resolveContainerPluginOptions.d.ts +2 -20
  83. package/lib/node/utils/resolveContainerPluginOptions.js +4 -66
  84. package/lib/shared/index.d.ts +3 -3
  85. package/lib/shared/index.js +3 -15
  86. package/lib/shared/nav.d.ts +16 -18
  87. package/lib/shared/nav.js +1 -2
  88. package/lib/shared/options.d.ts +51 -6
  89. package/lib/shared/options.js +1 -2
  90. package/lib/shared/page.d.ts +15 -6
  91. package/lib/shared/page.js +1 -2
  92. package/package.json +49 -29
  93. package/templates/build.html +34 -0
  94. package/CHANGELOG.md +0 -403
  95. package/lib/client/clientAppEnhance.d.ts +0 -3
  96. package/lib/client/clientAppEnhance.js +0 -30
  97. package/lib/client/clientAppSetup.d.ts +0 -2
  98. package/lib/client/clientAppSetup.js +0 -11
  99. package/lib/client/components/DropdownLink.vue +0 -141
  100. package/lib/client/components/NavLink.vue +0 -115
  101. package/lib/client/components/SidebarChild.d.ts +0 -6
  102. package/lib/client/components/SidebarChild.js +0 -91
  103. package/lib/client/components/global/OutboundLink.vue +0 -30
  104. package/lib/client/layouts/404.vue +0 -38
  105. package/lib/client/styles/_normalize.scss +0 -148
  106. package/lib/client/styles/plugins.scss +0 -18
  107. package/lib/client/styles/sr-only.scss +0 -12
  108. package/lib/node/utils/resolveActiveHeaderLinksPluginOptions.d.ts +0 -6
  109. package/lib/node/utils/resolveActiveHeaderLinksPluginOptions.js +0 -16
  110. package/lib/node/utils/resolveGitPluginOptions.d.ts +0 -6
  111. package/lib/node/utils/resolveGitPluginOptions.js +0 -22
  112. package/lib/node/utils/resolveMediumZoomPluginOptions.d.ts +0 -6
  113. package/lib/node/utils/resolveMediumZoomPluginOptions.js +0 -17
@@ -1,4 +1,4 @@
1
- import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
1
+ import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect.js';
2
2
  /**
3
3
  * Resolve NavLink props from string
4
4
  *
@@ -7,7 +7,10 @@ import { useResolveRouteWithRedirect } from './useResolveRouteWithRedirect';
7
7
  * - Output: { text: 'Home', link: '/' }
8
8
  */
9
9
  export const useNavLink = (item) => {
10
- const resolved = useResolveRouteWithRedirect(item);
10
+ // the route path of vue-router is url-encoded, and we expect users are using
11
+ // non-url-encoded string in theme config, so we need to url-encode it first to
12
+ // resolve the route correctly
13
+ const resolved = useResolveRouteWithRedirect(encodeURI(item));
11
14
  return {
12
15
  text: resolved.meta.title || item,
13
16
  link: resolved.name === '404' ? item : resolved.fullPath,
@@ -1,5 +1,5 @@
1
- import { useRouter } from 'vue-router';
2
1
  import { isFunction, isString } from '@vuepress/shared';
2
+ import { useRouter } from 'vue-router';
3
3
  /**
4
4
  * Resolve a route with redirection
5
5
  */
@@ -7,7 +7,7 @@ export const useResolveRouteWithRedirect = (...args) => {
7
7
  const router = useRouter();
8
8
  const route = router.resolve(...args);
9
9
  const lastMatched = route.matched[route.matched.length - 1];
10
- if (!(lastMatched === null || lastMatched === void 0 ? void 0 : lastMatched.redirect)) {
10
+ if (!lastMatched?.redirect) {
11
11
  return route;
12
12
  }
13
13
  const { redirect } = lastMatched;
@@ -6,7 +6,7 @@ const scrollPromise = {
6
6
  promise = new Promise((resolve) => (promiseResolve = resolve));
7
7
  },
8
8
  resolve: () => {
9
- promiseResolve === null || promiseResolve === void 0 ? void 0 : promiseResolve();
9
+ promiseResolve?.();
10
10
  promise = null;
11
11
  promiseResolve = null;
12
12
  },
@@ -1,31 +1,36 @@
1
- import type { ComputedRef, InjectionKey } from 'vue';
2
1
  import type { PageHeader } from '@vuepress/client';
3
- import type { DefaultThemeData, DefaultThemePageFrontmatter, SidebarConfigArray, SidebarConfigObject, ResolvedSidebarItem } from '../../shared';
4
- export declare type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
2
+ import type { ComputedRef, InjectionKey } from 'vue';
3
+ import type { DefaultThemeData, DefaultThemeNormalPageFrontmatter, ResolvedSidebarItem, SidebarConfigArray, SidebarConfigObject } from '../../shared/index.js';
4
+ export type SidebarItemsRef = ComputedRef<ResolvedSidebarItem[]>;
5
5
  export declare const sidebarItemsSymbol: InjectionKey<SidebarItemsRef>;
6
6
  /**
7
7
  * Inject sidebar items global computed
8
8
  */
9
9
  export declare const useSidebarItems: () => SidebarItemsRef;
10
+ /**
11
+ * Create sidebar items ref and provide as global computed in setup
12
+ */
13
+ export declare const setupSidebarItems: () => void;
10
14
  /**
11
15
  * Resolve sidebar items global computed
12
16
  *
13
17
  * It should only be resolved and provided once
14
18
  */
15
- export declare const resolveSidebarItems: (frontmatter: DefaultThemePageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
19
+ export declare const resolveSidebarItems: (frontmatter: DefaultThemeNormalPageFrontmatter, themeLocale: DefaultThemeData) => ResolvedSidebarItem[];
16
20
  /**
17
21
  * Util to transform page header to sidebar item
18
22
  */
19
- export declare const headerToSidebarItem: (header: PageHeader) => ResolvedSidebarItem;
23
+ export declare const headerToSidebarItem: (header: PageHeader, sidebarDepth: number) => ResolvedSidebarItem;
24
+ export declare const headersToSidebarItemChildren: (headers: PageHeader[], sidebarDepth: number) => ResolvedSidebarItem[];
20
25
  /**
21
26
  * Resolve sidebar items if the config is `auto`
22
27
  */
23
- export declare const resolveAutoSidebarItems: () => ResolvedSidebarItem[];
28
+ export declare const resolveAutoSidebarItems: (sidebarDepth: number) => ResolvedSidebarItem[];
24
29
  /**
25
30
  * Resolve sidebar items if the config is an array
26
31
  */
27
- export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray) => ResolvedSidebarItem[];
32
+ export declare const resolveArraySidebarItems: (sidebarConfig: SidebarConfigArray, sidebarDepth: number) => ResolvedSidebarItem[];
28
33
  /**
29
34
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
30
35
  */
31
- export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject) => ResolvedSidebarItem[];
36
+ export declare const resolveMultiSidebarItems: (sidebarConfig: SidebarConfigObject, sidebarDepth: number) => ResolvedSidebarItem[];
@@ -1,8 +1,9 @@
1
- import { inject } from 'vue';
2
- import { useRoute } from 'vue-router';
3
- import { usePageData } from '@vuepress/client';
1
+ import { usePageData, usePageFrontmatter } from '@vuepress/client';
4
2
  import { isArray, isPlainObject, isString, resolveLocalePath, } from '@vuepress/shared';
5
- import { useNavLink } from './useNavLink';
3
+ import { computed, inject, provide } from 'vue';
4
+ import { useRoute } from 'vue-router';
5
+ import { useNavLink } from './useNavLink.js';
6
+ import { useThemeLocaleData } from './useThemeData.js';
6
7
  export const sidebarItemsSymbol = Symbol('sidebarItems');
7
8
  /**
8
9
  * Inject sidebar items global computed
@@ -14,55 +15,66 @@ export const useSidebarItems = () => {
14
15
  }
15
16
  return sidebarItems;
16
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 sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value));
25
+ provide(sidebarItemsSymbol, sidebarItems);
26
+ };
17
27
  /**
18
28
  * Resolve sidebar items global computed
19
29
  *
20
30
  * It should only be resolved and provided once
21
31
  */
22
32
  export const resolveSidebarItems = (frontmatter, themeLocale) => {
23
- var _a, _b;
24
- // get sidebar config from frontmatter > themeConfig
25
- const sidebarConfig = (_b = (_a = frontmatter.sidebar) !== null && _a !== void 0 ? _a : themeLocale.sidebar) !== null && _b !== void 0 ? _b : 'auto';
33
+ // get sidebar config from frontmatter > theme data
34
+ const sidebarConfig = frontmatter.sidebar ?? themeLocale.sidebar ?? 'auto';
35
+ const sidebarDepth = frontmatter.sidebarDepth ?? themeLocale.sidebarDepth ?? 2;
26
36
  // resolve sidebar items according to the config
27
- if (frontmatter.home === true || sidebarConfig === false) {
37
+ if (frontmatter.home || sidebarConfig === false) {
28
38
  return [];
29
39
  }
30
40
  if (sidebarConfig === 'auto') {
31
- return resolveAutoSidebarItems();
41
+ return resolveAutoSidebarItems(sidebarDepth);
32
42
  }
33
43
  if (isArray(sidebarConfig)) {
34
- return resolveArraySidebarItems(sidebarConfig);
44
+ return resolveArraySidebarItems(sidebarConfig, sidebarDepth);
35
45
  }
36
46
  if (isPlainObject(sidebarConfig)) {
37
- return resolveMultiSidebarItems(sidebarConfig);
47
+ return resolveMultiSidebarItems(sidebarConfig, sidebarDepth);
38
48
  }
39
49
  return [];
40
50
  };
41
51
  /**
42
52
  * Util to transform page header to sidebar item
43
53
  */
44
- export const headerToSidebarItem = (header) => ({
54
+ export const headerToSidebarItem = (header, sidebarDepth) => ({
45
55
  text: header.title,
46
- link: `#${header.slug}`,
47
- children: header.children.map(headerToSidebarItem),
56
+ link: header.link,
57
+ children: headersToSidebarItemChildren(header.children, sidebarDepth),
48
58
  });
59
+ export const headersToSidebarItemChildren = (headers, sidebarDepth) => sidebarDepth > 0
60
+ ? headers.map((header) => headerToSidebarItem(header, sidebarDepth - 1))
61
+ : [];
49
62
  /**
50
63
  * Resolve sidebar items if the config is `auto`
51
64
  */
52
- export const resolveAutoSidebarItems = () => {
65
+ export const resolveAutoSidebarItems = (sidebarDepth) => {
53
66
  const page = usePageData();
54
67
  return [
55
68
  {
56
- isGroup: true,
57
69
  text: page.value.title,
58
- children: page.value.headers.map(headerToSidebarItem),
70
+ children: headersToSidebarItemChildren(page.value.headers, sidebarDepth),
59
71
  },
60
72
  ];
61
73
  };
62
74
  /**
63
75
  * Resolve sidebar items if the config is an array
64
76
  */
65
- export const resolveArraySidebarItems = (sidebarConfig) => {
77
+ export const resolveArraySidebarItems = (sidebarConfig, sidebarDepth) => {
66
78
  const route = useRoute();
67
79
  const page = usePageData();
68
80
  const handleChildItem = (item) => {
@@ -73,42 +85,34 @@ export const resolveArraySidebarItems = (sidebarConfig) => {
73
85
  else {
74
86
  childItem = item;
75
87
  }
76
- if (childItem.isGroup && childItem.children) {
88
+ if (childItem.children) {
77
89
  return {
78
90
  ...childItem,
79
- children: childItem.children.map(handleChildItem),
91
+ children: childItem.children.map((item) => handleChildItem(item)),
80
92
  };
81
93
  }
82
94
  // if the sidebar item is current page and children is not set
83
95
  // use headers of current page as children
84
- if (childItem.link === route.path && childItem.children === undefined) {
96
+ if (childItem.link === route.path) {
97
+ // skip h1 header
98
+ const headers = page.value.headers[0]?.level === 1
99
+ ? page.value.headers[0].children
100
+ : page.value.headers;
85
101
  return {
86
102
  ...childItem,
87
- children: page.value.headers.map(headerToSidebarItem),
103
+ children: headersToSidebarItemChildren(headers, sidebarDepth),
88
104
  };
89
105
  }
90
106
  return childItem;
91
107
  };
92
- return sidebarConfig.map((item) => {
93
- if (isString(item)) {
94
- return useNavLink(item);
95
- }
96
- if (!item.isGroup) {
97
- return item;
98
- }
99
- return {
100
- ...item,
101
- children: item.children.map(handleChildItem),
102
- };
103
- });
108
+ return sidebarConfig.map((item) => handleChildItem(item));
104
109
  };
105
110
  /**
106
111
  * Resolve sidebar items if the config is a key -> value (path-prefix -> array) object
107
112
  */
108
- export const resolveMultiSidebarItems = (sidebarConfig) => {
109
- var _a;
113
+ export const resolveMultiSidebarItems = (sidebarConfig, sidebarDepth) => {
110
114
  const route = useRoute();
111
115
  const sidebarPath = resolveLocalePath(sidebarConfig, route.path);
112
- const matchedSidebarConfig = (_a = sidebarConfig[sidebarPath]) !== null && _a !== void 0 ? _a : [];
113
- return resolveArraySidebarItems(matchedSidebarConfig);
116
+ const matchedSidebarConfig = sidebarConfig[sidebarPath] ?? [];
117
+ return resolveArraySidebarItems(matchedSidebarConfig, sidebarDepth);
114
118
  };
@@ -1,4 +1,4 @@
1
- import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/lib/client';
2
- import type { DefaultThemeData } from '../../shared';
1
+ import type { ThemeDataRef, ThemeLocaleDataRef } from '@vuepress/plugin-theme-data/client';
2
+ import type { DefaultThemeData } from '../../shared/index.js';
3
3
  export declare const useThemeData: () => ThemeDataRef<DefaultThemeData>;
4
4
  export declare const useThemeLocaleData: () => ThemeLocaleDataRef<DefaultThemeData>;
@@ -1,3 +1,3 @@
1
- import { useThemeData as _useThemeData, useThemeLocaleData as _useThemeLocaleData, } from '@vuepress/plugin-theme-data/lib/client';
1
+ import { useThemeData as _useThemeData, useThemeLocaleData as _useThemeLocaleData, } from '@vuepress/plugin-theme-data/client';
2
2
  export const useThemeData = () => _useThemeData();
3
3
  export const useThemeLocaleData = () => _useThemeLocaleData();
@@ -0,0 +1,7 @@
1
+ export declare enum DeviceType {
2
+ MOBILE = "mobile"
3
+ }
4
+ /**
5
+ * add listener to detect screen though device type
6
+ */
7
+ export declare const useUpdateDeviceStatus: (deviceType: DeviceType, callback: (width: number) => void) => void;
@@ -0,0 +1,25 @@
1
+ import { onMounted } from 'vue';
2
+ import cssVars from '../styles/_variables.module.scss?module';
3
+ export var DeviceType;
4
+ (function (DeviceType) {
5
+ DeviceType["MOBILE"] = "mobile";
6
+ })(DeviceType || (DeviceType = {}));
7
+ const DeviceTypeMap = {
8
+ [DeviceType.MOBILE]: Number.parseInt(cssVars.mobile?.replace('px', ''), 10),
9
+ };
10
+ /**
11
+ * add listener to detect screen though device type
12
+ */
13
+ export const useUpdateDeviceStatus = (deviceType, callback) => {
14
+ const width = DeviceTypeMap[deviceType];
15
+ if (!Number.isInteger(width)) {
16
+ if (__VUEPRESS_DEV__)
17
+ throw new Error('device width must be a integer');
18
+ return;
19
+ }
20
+ onMounted(() => {
21
+ callback(width);
22
+ window.addEventListener('resize', () => callback(width), false);
23
+ window.addEventListener('orientationchange', () => callback(width), false);
24
+ });
25
+ };
@@ -0,0 +1,3 @@
1
+ import './styles/index.scss';
2
+ declare const _default: import("@vuepress/client").ClientConfig;
3
+ export default _default;
@@ -0,0 +1,44 @@
1
+ import { defineClientConfig } from '@vuepress/client';
2
+ import { h } from 'vue';
3
+ import { Badge, CodeGroup, CodeGroupItem } from './components/global/index.js';
4
+ import { setupDarkMode, setupSidebarItems, useScrollPromise, } from './composables/index.js';
5
+ import Layout from './layouts/Layout.vue';
6
+ import NotFound from './layouts/NotFound.vue';
7
+ import './styles/index.scss';
8
+ export default defineClientConfig({
9
+ enhance({ app, router }) {
10
+ app.component('Badge', Badge);
11
+ app.component('CodeGroup', CodeGroup);
12
+ app.component('CodeGroupItem', CodeGroupItem);
13
+ // compat with @vuepress/plugin-external-link-icon
14
+ app.component('AutoLinkExternalIcon', () => {
15
+ const ExternalLinkIcon = app.component('ExternalLinkIcon');
16
+ if (ExternalLinkIcon) {
17
+ return h(ExternalLinkIcon);
18
+ }
19
+ return null;
20
+ });
21
+ // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
22
+ app.component('NavbarSearch', () => {
23
+ const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
24
+ if (SearchComponent) {
25
+ return h(SearchComponent);
26
+ }
27
+ return null;
28
+ });
29
+ // handle scrollBehavior with transition
30
+ const scrollBehavior = router.options.scrollBehavior;
31
+ router.options.scrollBehavior = async (...args) => {
32
+ await useScrollPromise().wait();
33
+ return scrollBehavior(...args);
34
+ };
35
+ },
36
+ setup() {
37
+ setupDarkMode();
38
+ setupSidebarItems();
39
+ },
40
+ layouts: {
41
+ Layout,
42
+ NotFound,
43
+ },
44
+ });
@@ -1,4 +1,3 @@
1
- import type { NavItem, NavGroup, NavLink, NavbarItem, NavbarGroup, NavbarConfig, ResolvedNavbarItem, SidebarItem, SidebarGroup, SidebarConfigArray, SidebarConfigObject, SidebarConfig, ResolvedSidebarItem, DefaultThemePluginsOptions, DefaultThemeLocaleOptions, DefaultThemeData, DefaultThemeLocaleData, DefaultThemePageData, DefaultThemeHomePageFrontmatter, DefaultThemePageFrontmatter } from '../shared';
2
- export type { NavItem, NavGroup, NavLink, NavbarItem, NavbarGroup, NavbarConfig, ResolvedNavbarItem, SidebarItem, SidebarGroup, SidebarConfigArray, SidebarConfigObject, SidebarConfig, ResolvedSidebarItem, DefaultThemePluginsOptions, DefaultThemeLocaleOptions, DefaultThemeData, DefaultThemeLocaleData, DefaultThemePageData, DefaultThemeHomePageFrontmatter, DefaultThemePageFrontmatter, };
3
- export * from './composables';
4
- export * from './utils';
1
+ export * from '../shared/index.js';
2
+ export * from './composables/index.js';
3
+ export * from './utils/index.js';
@@ -1,2 +1,3 @@
1
- export * from './composables';
2
- export * from './utils';
1
+ export * from '../shared/index.js';
2
+ export * from './composables/index.js';
3
+ export * from './utils/index.js';
@@ -1,3 +1,93 @@
1
+ <script setup lang="ts">
2
+ import Home from '@theme/Home.vue'
3
+ import Navbar from '@theme/Navbar.vue'
4
+ import Page from '@theme/Page.vue'
5
+ import Sidebar from '@theme/Sidebar.vue'
6
+ import { usePageData, usePageFrontmatter } from '@vuepress/client'
7
+ import { computed, onMounted, onUnmounted, ref } from 'vue'
8
+ import { useRouter } from 'vue-router'
9
+ import type { DefaultThemePageFrontmatter } from '../../shared/index.js'
10
+ import {
11
+ useScrollPromise,
12
+ useSidebarItems,
13
+ useThemeLocaleData,
14
+ } from '../composables/index.js'
15
+
16
+ defineSlots<{
17
+ 'navbar'?: (props: Record<never, never>) => any
18
+ 'navbar-before'?: (props: Record<never, never>) => any
19
+ 'navbar-after'?: (props: Record<never, never>) => any
20
+ 'sidebar'?: (props: Record<never, never>) => any
21
+ 'sidebar-top'?: (props: Record<never, never>) => any
22
+ 'sidebar-bottom'?: (props: Record<never, never>) => any
23
+ 'page'?: (props: Record<never, never>) => any
24
+ 'page-top'?: (props: Record<never, never>) => any
25
+ 'page-bottom'?: (props: Record<never, never>) => any
26
+ 'page-content-top'?: (props: Record<never, never>) => any
27
+ 'page-content-bottom'?: (props: Record<never, never>) => any
28
+ }>()
29
+
30
+ const page = usePageData()
31
+ const frontmatter = usePageFrontmatter<DefaultThemePageFrontmatter>()
32
+ const themeLocale = useThemeLocaleData()
33
+
34
+ // navbar
35
+ const shouldShowNavbar = computed(
36
+ () =>
37
+ frontmatter.value.navbar !== false && themeLocale.value.navbar !== false,
38
+ )
39
+
40
+ // sidebar
41
+ const sidebarItems = useSidebarItems()
42
+ const isSidebarOpen = ref(false)
43
+ const toggleSidebar = (to?: boolean): void => {
44
+ isSidebarOpen.value = typeof to === 'boolean' ? to : !isSidebarOpen.value
45
+ }
46
+ const touchStart = { x: 0, y: 0 }
47
+ const onTouchStart = (e): void => {
48
+ touchStart.x = e.changedTouches[0].clientX
49
+ touchStart.y = e.changedTouches[0].clientY
50
+ }
51
+ const onTouchEnd = (e): void => {
52
+ const dx = e.changedTouches[0].clientX - touchStart.x
53
+ const dy = e.changedTouches[0].clientY - touchStart.y
54
+ if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
55
+ if (dx > 0 && touchStart.x <= 80) {
56
+ toggleSidebar(true)
57
+ } else {
58
+ toggleSidebar(false)
59
+ }
60
+ }
61
+ }
62
+
63
+ // classes
64
+ const containerClass = computed(() => [
65
+ {
66
+ 'no-navbar': !shouldShowNavbar.value,
67
+ 'no-sidebar': !sidebarItems.value.length,
68
+ 'sidebar-open': isSidebarOpen.value,
69
+ },
70
+ frontmatter.value.pageClass,
71
+ ])
72
+
73
+ // close sidebar after navigation
74
+ let unregisterRouterHook
75
+ onMounted(() => {
76
+ const router = useRouter()
77
+ unregisterRouterHook = router.afterEach(() => {
78
+ toggleSidebar(false)
79
+ })
80
+ })
81
+ onUnmounted(() => {
82
+ unregisterRouterHook()
83
+ })
84
+
85
+ // handle scrollBehavior with transition
86
+ const scrollPromise = useScrollPromise()
87
+ const onBeforeEnter = scrollPromise.resolve
88
+ const onBeforeLeave = scrollPromise.pending
89
+ </script>
90
+
1
91
  <template>
2
92
  <div
3
93
  class="theme-container"
@@ -5,148 +95,55 @@
5
95
  @touchstart="onTouchStart"
6
96
  @touchend="onTouchEnd"
7
97
  >
8
- <Navbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar">
9
- <template #before>
10
- <slot name="navbar-before" />
11
- </template>
12
- <template #after>
13
- <slot name="navbar-after" />
14
- </template>
15
- </Navbar>
98
+ <slot name="navbar">
99
+ <Navbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar">
100
+ <template #before>
101
+ <slot name="navbar-before" />
102
+ </template>
103
+ <template #after>
104
+ <slot name="navbar-after" />
105
+ </template>
106
+ </Navbar>
107
+ </slot>
16
108
 
17
109
  <div class="sidebar-mask" @click="toggleSidebar(false)" />
18
110
 
19
- <Sidebar>
20
- <template #top>
21
- <slot name="sidebar-top" />
22
- </template>
23
- <template #bottom>
24
- <slot name="sidebar-bottom" />
25
- </template>
26
- </Sidebar>
27
-
28
- <Home v-if="frontmatter.home" />
29
-
30
- <Transition
31
- v-else
32
- name="fade-slide-y"
33
- mode="out-in"
34
- @before-enter="onBeforeEnter"
35
- @before-leave="onBeforeLeave"
36
- >
37
- <Page :key="page.path">
111
+ <slot name="sidebar">
112
+ <Sidebar>
38
113
  <template #top>
39
- <slot name="page-top" />
114
+ <slot name="sidebar-top" />
40
115
  </template>
41
116
  <template #bottom>
42
- <slot name="page-bottom" />
117
+ <slot name="sidebar-bottom" />
43
118
  </template>
44
- </Page>
45
- </Transition>
46
- </div>
47
- </template>
119
+ </Sidebar>
120
+ </slot>
48
121
 
49
- <script lang="ts">
50
- import {
51
- computed,
52
- defineComponent,
53
- onMounted,
54
- onUnmounted,
55
- ref,
56
- Transition,
57
- } from 'vue'
58
- import { useRouter } from 'vue-router'
59
- import { usePageData, usePageFrontmatter } from '@vuepress/client'
60
- import Home from '../components/Home.vue'
61
- import Page from '../components/Page.vue'
62
- import Navbar from '../components/Navbar.vue'
63
- import Sidebar from '../components/Sidebar.vue'
64
- import {
65
- useScrollPromise,
66
- useSidebarItems,
67
- useThemeLocaleData,
68
- } from '../composables'
122
+ <slot name="page">
123
+ <Home v-if="frontmatter.home" />
69
124
 
70
- export default defineComponent({
71
- name: 'Layout',
72
-
73
- components: {
74
- Home,
75
- Page,
76
- Navbar,
77
- Sidebar,
78
- Transition,
79
- },
80
-
81
- setup() {
82
- const page = usePageData()
83
- const frontmatter = usePageFrontmatter()
84
- const themeLocale = useThemeLocaleData()
85
-
86
- // navbar
87
- const shouldShowNavbar = computed(
88
- () =>
89
- frontmatter.value.navbar !== false && themeLocale.value.navbar !== false
90
- )
91
-
92
- // sidebar
93
- const sidebarItems = useSidebarItems()
94
- const isSidebarOpen = ref(false)
95
- const toggleSidebar = (to?: boolean): void => {
96
- isSidebarOpen.value = typeof to === 'boolean' ? to : !isSidebarOpen.value
97
- }
98
- const touchStart = { x: 0, y: 0 }
99
- const onTouchStart = (e): void => {
100
- touchStart.x = e.changedTouches[0].clientX
101
- touchStart.y = e.changedTouches[0].clientY
102
- }
103
- const onTouchEnd = (e): void => {
104
- const dx = e.changedTouches[0].clientX - touchStart.x
105
- const dy = e.changedTouches[0].clientY - touchStart.y
106
- if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
107
- if (dx > 0 && touchStart.x <= 80) {
108
- toggleSidebar(true)
109
- } else {
110
- toggleSidebar(false)
111
- }
112
- }
113
- }
114
-
115
- // classes
116
- const containerClass = computed(() => ({
117
- 'no-navbar': !shouldShowNavbar.value,
118
- 'no-sidebar': !sidebarItems.value.length,
119
- 'sidebar-open': isSidebarOpen.value,
120
- }))
121
-
122
- // close sidebar after navigation
123
- let unregisterRouterHook
124
- onMounted(() => {
125
- const router = useRouter()
126
- unregisterRouterHook = router.afterEach(() => {
127
- toggleSidebar(false)
128
- })
129
- })
130
- onUnmounted(() => {
131
- unregisterRouterHook()
132
- })
133
-
134
- // handle scrollBehavior with transition
135
- const scrollPromise = useScrollPromise()
136
- const onBeforeEnter = scrollPromise.resolve
137
- const onBeforeLeave = scrollPromise.pending
138
-
139
- return {
140
- frontmatter,
141
- page,
142
- containerClass,
143
- shouldShowNavbar,
144
- toggleSidebar,
145
- onTouchStart,
146
- onTouchEnd,
147
- onBeforeEnter,
148
- onBeforeLeave,
149
- }
150
- },
151
- })
152
- </script>
125
+ <Transition
126
+ v-else
127
+ name="fade-slide-y"
128
+ mode="out-in"
129
+ @before-enter="onBeforeEnter"
130
+ @before-leave="onBeforeLeave"
131
+ >
132
+ <Page :key="page.path">
133
+ <template #top>
134
+ <slot name="page-top" />
135
+ </template>
136
+ <template #content-top>
137
+ <slot name="page-content-top" />
138
+ </template>
139
+ <template #content-bottom>
140
+ <slot name="page-content-bottom" />
141
+ </template>
142
+ <template #bottom>
143
+ <slot name="page-bottom" />
144
+ </template>
145
+ </Page>
146
+ </Transition>
147
+ </slot>
148
+ </div>
149
+ </template>
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ import { useRouteLocale } from '@vuepress/client'
3
+ import { useThemeLocaleData } from '../composables/index.js'
4
+
5
+ const routeLocale = useRouteLocale()
6
+ const themeLocale = useThemeLocaleData()
7
+
8
+ const messages = themeLocale.value.notFound ?? ['Not Found']
9
+ const getMsg = (): string =>
10
+ messages[Math.floor(Math.random() * messages.length)]
11
+ const homeLink = themeLocale.value.home ?? routeLocale.value
12
+ const homeText = themeLocale.value.backToHome ?? 'Back to home'
13
+ </script>
14
+
15
+ <template>
16
+ <div class="theme-container">
17
+ <main class="page">
18
+ <div class="theme-default-content">
19
+ <h1>404</h1>
20
+
21
+ <blockquote>{{ getMsg() }}</blockquote>
22
+
23
+ <RouterLink :to="homeLink">{{ homeText }}</RouterLink>
24
+ </div>
25
+ </main>
26
+ </div>
27
+ </template>