@vuepress/theme-default 2.0.0-beta.61 → 2.0.0-beta.63

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.
@@ -23,6 +23,11 @@ const props = defineProps({
23
23
  },
24
24
  })
25
25
 
26
+ defineSlots<{
27
+ before?: (props: Record<never, never>) => any
28
+ after?: (props: Record<never, never>) => any
29
+ }>()
30
+
26
31
  const route = useRoute()
27
32
  const site = useSiteData()
28
33
  const { item } = toRefs(props)
@@ -1,4 +1,8 @@
1
1
  <script setup lang="ts">
2
+ defineSlots<{
3
+ default?: (props: Record<never, never>) => any
4
+ }>()
5
+
2
6
  const setHeight = (items): void => {
3
7
  // explicitly set height so that it can be transitioned
4
8
  items.style.height = items.scrollHeight + 'px'
@@ -3,10 +3,21 @@ import NavbarBrand from '@theme/NavbarBrand.vue'
3
3
  import NavbarItems from '@theme/NavbarItems.vue'
4
4
  import ToggleColorModeButton from '@theme/ToggleColorModeButton.vue'
5
5
  import ToggleSidebarButton from '@theme/ToggleSidebarButton.vue'
6
- import { computed, onMounted, ref } from 'vue'
7
- import { useThemeLocaleData } from '../composables/index.js'
6
+ import { computed, ref } from 'vue'
7
+ import {
8
+ DeviceType,
9
+ useThemeLocaleData,
10
+ useUpdateDeviceStatus,
11
+ } from '../composables/index.js'
8
12
 
9
- defineEmits(['toggle-sidebar'])
13
+ defineEmits<{
14
+ (e: 'toggle-sidebar'): void
15
+ }>()
16
+
17
+ defineSlots<{
18
+ before?: (props: Record<never, never>) => any
19
+ after?: (props: Record<never, never>) => any
20
+ }>()
10
21
 
11
22
  const themeLocale = useThemeLocaleData()
12
23
 
@@ -23,16 +34,14 @@ const linksWrapperStyle = computed(() => {
23
34
  }
24
35
  })
25
36
 
26
- // avoid overlapping of long title and long navbar links
27
- onMounted(() => {
28
- // TODO: migrate to css var
29
- // refer to _variables.scss
30
- const MOBILE_DESKTOP_BREAKPOINT = 719
31
- const navbarHorizontalPadding =
32
- getCssValue(navbar.value, 'paddingLeft') +
33
- getCssValue(navbar.value, 'paddingRight')
34
- const handleLinksWrapWidth = (): void => {
35
- if (window.innerWidth < MOBILE_DESKTOP_BREAKPOINT) {
37
+ useUpdateDeviceStatus(
38
+ DeviceType.MOBILE,
39
+ (mobileDesktopBreakpoint: number): void => {
40
+ // avoid overlapping of long title and long navbar links
41
+ const navbarHorizontalPadding =
42
+ getCssValue(navbar.value, 'paddingLeft') +
43
+ getCssValue(navbar.value, 'paddingRight')
44
+ if (window.innerWidth < mobileDesktopBreakpoint) {
36
45
  linksWrapperMaxWidth.value = 0
37
46
  } else {
38
47
  linksWrapperMaxWidth.value =
@@ -41,10 +50,7 @@ onMounted(() => {
41
50
  (navbarBrand.value?.offsetWidth || 0)
42
51
  }
43
52
  }
44
- handleLinksWrapWidth()
45
- window.addEventListener('resize', handleLinksWrapWidth, false)
46
- window.addEventListener('orientationchange', handleLinksWrapWidth, false)
47
- })
53
+ )
48
54
 
49
55
  function getCssValue(el: HTMLElement | null, property: string): number {
50
56
  // NOTE: Known bug, will return 'auto' if style value is 'auto'
@@ -1,9 +1,13 @@
1
1
  <script setup lang="ts">
2
2
  import AutoLink from '@theme/AutoLink.vue'
3
3
  import NavbarDropdown from '@theme/NavbarDropdown.vue'
4
- import { useRouteLocale, useSiteLocaleData } from '@vuepress/client'
4
+ import {
5
+ useRouteLocale,
6
+ useSiteData,
7
+ useSiteLocaleData,
8
+ } from '@vuepress/client'
5
9
  import { isLinkHttp, isString } from '@vuepress/shared'
6
- import { computed, onMounted, ref } from 'vue'
10
+ import { computed, ref } from 'vue'
7
11
  import type { ComputedRef } from 'vue'
8
12
  import { useRouter } from 'vue-router'
9
13
  import type {
@@ -11,7 +15,13 @@ import type {
11
15
  NavbarItem,
12
16
  ResolvedNavbarItem,
13
17
  } from '../../shared/index.js'
14
- import { useNavLink, useThemeLocaleData } from '../composables/index.js'
18
+ import {
19
+ DeviceType,
20
+ useNavLink,
21
+ useThemeData,
22
+ useThemeLocaleData,
23
+ useUpdateDeviceStatus,
24
+ } from '../composables/index.js'
15
25
  import { resolveRepoType } from '../utils/index.js'
16
26
 
17
27
  /**
@@ -20,11 +30,13 @@ import { resolveRepoType } from '../utils/index.js'
20
30
  const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
21
31
  const router = useRouter()
22
32
  const routeLocale = useRouteLocale()
33
+ const site = useSiteData()
23
34
  const siteLocale = useSiteLocaleData()
35
+ const theme = useThemeData()
24
36
  const themeLocale = useThemeLocaleData()
25
37
 
26
38
  return computed<ResolvedNavbarItem[]>(() => {
27
- const localePaths = Object.keys(siteLocale.value.locales)
39
+ const localePaths = Object.keys(site.value.locales)
28
40
  // do not display language selection dropdown if there is only one language
29
41
  if (localePaths.length < 2) {
30
42
  return []
@@ -33,17 +45,15 @@ const useNavbarSelectLanguage = (): ComputedRef<ResolvedNavbarItem[]> => {
33
45
  const currentFullPath = router.currentRoute.value.fullPath
34
46
 
35
47
  const languageDropdown: ResolvedNavbarItem = {
36
- text: themeLocale.value.selectLanguageText ?? 'unknown language',
37
- ariaLabel:
48
+ text: `${themeLocale.value.selectLanguageText}`,
49
+ ariaLabel: `${
38
50
  themeLocale.value.selectLanguageAriaLabel ??
39
- themeLocale.value.selectLanguageText ??
40
- 'unknown language',
51
+ themeLocale.value.selectLanguageText
52
+ }`,
41
53
  children: localePaths.map((targetLocalePath) => {
42
54
  // target locale config of this language link
43
- const targetSiteLocale =
44
- siteLocale.value.locales?.[targetLocalePath] ?? {}
45
- const targetThemeLocale =
46
- themeLocale.value.locales?.[targetLocalePath] ?? {}
55
+ const targetSiteLocale = site.value.locales?.[targetLocalePath] ?? {}
56
+ const targetThemeLocale = theme.value.locales?.[targetLocalePath] ?? {}
47
57
  const targetLang = `${targetSiteLocale.lang}`
48
58
 
49
59
  const text = targetThemeLocale.selectLanguageName ?? targetLang
@@ -152,23 +162,17 @@ const navbarLinks = computed(() => [
152
162
  ...navbarRepo.value,
153
163
  ])
154
164
 
155
- // avoid overlapping of long title and long navbar links
156
- onMounted(() => {
157
- // TODO: migrate to css var
158
- // refer to _variables.scss
159
- const MOBILE_DESKTOP_BREAKPOINT = 719
160
-
161
- const handleMobile = (): void => {
162
- if (window.innerWidth < MOBILE_DESKTOP_BREAKPOINT) {
165
+ useUpdateDeviceStatus(
166
+ DeviceType.MOBILE,
167
+ (mobileDesktopBreakpoint: number): void => {
168
+ // avoid overlapping of long title and long navbar links
169
+ if (window.innerWidth < mobileDesktopBreakpoint) {
163
170
  isMobile.value = true
164
171
  } else {
165
172
  isMobile.value = false
166
173
  }
167
174
  }
168
- handleMobile()
169
- window.addEventListener('resize', handleMobile, false)
170
- window.addEventListener('orientationchange', handleMobile, false)
171
- })
175
+ )
172
176
  </script>
173
177
 
174
178
  <template>
@@ -1,6 +1,13 @@
1
1
  <script setup lang="ts">
2
2
  import PageMeta from '@theme/PageMeta.vue'
3
3
  import PageNav from '@theme/PageNav.vue'
4
+
5
+ defineSlots<{
6
+ 'top'?: (props: Record<never, never>) => any
7
+ 'bottom'?: (props: Record<never, never>) => any
8
+ 'content-top'?: (props: Record<never, never>) => any
9
+ 'content-bottom'?: (props: Record<never, never>) => any
10
+ }>()
4
11
  </script>
5
12
 
6
13
  <template>
@@ -1,6 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  import NavbarItems from '@theme/NavbarItems.vue'
3
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
+ }>()
4
9
  </script>
5
10
 
6
11
  <template>
@@ -1,7 +1,9 @@
1
1
  <script setup lang="ts">
2
2
  import { useThemeLocaleData } from '../composables/index.js'
3
3
 
4
- defineEmits(['toggle'])
4
+ defineEmits<{
5
+ (e: 'toggle'): void
6
+ }>()
5
7
 
6
8
  const themeLocale = useThemeLocaleData()
7
9
  </script>
@@ -16,6 +16,10 @@ defineProps({
16
16
  default: undefined,
17
17
  },
18
18
  })
19
+
20
+ defineSlots<{
21
+ default?: () => any
22
+ }>()
19
23
  </script>
20
24
 
21
25
  <template>
@@ -1,4 +1,6 @@
1
- import type { VNode } from 'vue';
1
+ import type { SlotsType, VNode } from 'vue';
2
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, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
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,6 +1,7 @@
1
1
  import { defineComponent, h, onBeforeUpdate, ref } from 'vue';
2
2
  export const CodeGroup = defineComponent({
3
3
  name: 'CodeGroup',
4
+ slots: Object,
4
5
  setup(_, { slots }) {
5
6
  // index of current active item
6
7
  const activeIndex = ref(-1);
@@ -4,3 +4,4 @@ export * from './useResolveRouteWithRedirect.js';
4
4
  export * from './useScrollPromise.js';
5
5
  export * from './useSidebarItems.js';
6
6
  export * from './useThemeData.js';
7
+ export * from './useUpdateDeviceStatus.js';
@@ -4,3 +4,4 @@ export * from './useResolveRouteWithRedirect.js';
4
4
  export * from './useScrollPromise.js';
5
5
  export * from './useSidebarItems.js';
6
6
  export * from './useThemeData.js';
7
+ export * from './useUpdateDeviceStatus.js';
@@ -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
+ };
@@ -13,6 +13,20 @@ import {
13
13
  useThemeLocaleData,
14
14
  } from '../composables/index.js'
15
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
+
16
30
  const page = usePageData()
17
31
  const frontmatter = usePageFrontmatter<DefaultThemePageFrontmatter>()
18
32
  const themeLocale = useThemeLocaleData()
@@ -3,3 +3,8 @@ declare module '*.vue' {
3
3
  const comp: ComponentOptions
4
4
  export default comp
5
5
  }
6
+
7
+ declare module '*.module.scss?module' {
8
+ const cssVars: Record<string, string>
9
+ export default cssVars
10
+ }
@@ -0,0 +1,5 @@
1
+ @import '_variables';
2
+
3
+ :export {
4
+ mobile: $MQMobile;
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/theme-default",
3
- "version": "2.0.0-beta.61",
3
+ "version": "2.0.0-beta.63",
4
4
  "description": "Default theme of VuePress",
5
5
  "keywords": [
6
6
  "vuepress-theme",
@@ -36,27 +36,28 @@
36
36
  "templates"
37
37
  ],
38
38
  "dependencies": {
39
- "@vueuse/core": "^9.13.0",
40
- "sass": "^1.58.3",
41
- "vue": "^3.2.47",
42
- "vue-router": "^4.1.6",
43
- "@vuepress/client": "2.0.0-beta.61",
44
- "@vuepress/core": "2.0.0-beta.61",
45
- "@vuepress/plugin-active-header-links": "2.0.0-beta.61",
46
- "@vuepress/plugin-container": "2.0.0-beta.61",
47
- "@vuepress/plugin-back-to-top": "2.0.0-beta.61",
48
- "@vuepress/plugin-external-link-icon": "2.0.0-beta.61",
49
- "@vuepress/plugin-git": "2.0.0-beta.61",
50
- "@vuepress/plugin-medium-zoom": "2.0.0-beta.61",
51
- "@vuepress/plugin-nprogress": "2.0.0-beta.61",
52
- "@vuepress/plugin-palette": "2.0.0-beta.61",
53
- "@vuepress/plugin-prismjs": "2.0.0-beta.61",
54
- "@vuepress/utils": "2.0.0-beta.61",
55
- "@vuepress/plugin-theme-data": "2.0.0-beta.61",
56
- "@vuepress/shared": "2.0.0-beta.61"
39
+ "@vueuse/core": "^10.1.2",
40
+ "sass": "^1.63.2",
41
+ "sass-loader": "^13.3.1",
42
+ "vue": "^3.3.4",
43
+ "vue-router": "^4.2.2",
44
+ "@vuepress/client": "2.0.0-beta.63",
45
+ "@vuepress/plugin-back-to-top": "2.0.0-beta.63",
46
+ "@vuepress/plugin-active-header-links": "2.0.0-beta.63",
47
+ "@vuepress/plugin-container": "2.0.0-beta.63",
48
+ "@vuepress/plugin-external-link-icon": "2.0.0-beta.63",
49
+ "@vuepress/plugin-medium-zoom": "2.0.0-beta.63",
50
+ "@vuepress/plugin-git": "2.0.0-beta.63",
51
+ "@vuepress/plugin-nprogress": "2.0.0-beta.63",
52
+ "@vuepress/core": "2.0.0-beta.63",
53
+ "@vuepress/plugin-palette": "2.0.0-beta.63",
54
+ "@vuepress/plugin-prismjs": "2.0.0-beta.63",
55
+ "@vuepress/utils": "2.0.0-beta.63",
56
+ "@vuepress/plugin-theme-data": "2.0.0-beta.63",
57
+ "@vuepress/shared": "2.0.0-beta.63"
57
58
  },
58
59
  "peerDependencies": {
59
- "sass-loader": "^13.2.0"
60
+ "sass-loader": "^13.2.1"
60
61
  },
61
62
  "peerDependenciesMeta": {
62
63
  "sass-loader": {