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

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'
@@ -3,7 +3,7 @@ import AutoLink from '@theme/AutoLink.vue'
3
3
  import NavbarDropdown from '@theme/NavbarDropdown.vue'
4
4
  import { useRouteLocale, useSiteLocaleData } from '@vuepress/client'
5
5
  import { isLinkHttp, isString } from '@vuepress/shared'
6
- import { computed, onMounted, ref } from 'vue'
6
+ import { computed, ref } from 'vue'
7
7
  import type { ComputedRef } from 'vue'
8
8
  import { useRouter } from 'vue-router'
9
9
  import type {
@@ -11,7 +11,12 @@ import type {
11
11
  NavbarItem,
12
12
  ResolvedNavbarItem,
13
13
  } from '../../shared/index.js'
14
- import { useNavLink, useThemeLocaleData } from '../composables/index.js'
14
+ import {
15
+ DeviceType,
16
+ useNavLink,
17
+ useThemeLocaleData,
18
+ useUpdateDeviceStatus,
19
+ } from '../composables/index.js'
15
20
  import { resolveRepoType } from '../utils/index.js'
16
21
 
17
22
  /**
@@ -152,23 +157,17 @@ const navbarLinks = computed(() => [
152
157
  ...navbarRepo.value,
153
158
  ])
154
159
 
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) {
160
+ useUpdateDeviceStatus(
161
+ DeviceType.MOBILE,
162
+ (mobileDesktopBreakpoint: number): void => {
163
+ // avoid overlapping of long title and long navbar links
164
+ if (window.innerWidth < mobileDesktopBreakpoint) {
163
165
  isMobile.value = true
164
166
  } else {
165
167
  isMobile.value = false
166
168
  }
167
169
  }
168
- handleMobile()
169
- window.addEventListener('resize', handleMobile, false)
170
- window.addEventListener('orientationchange', handleMobile, false)
171
- })
170
+ )
172
171
  </script>
173
172
 
174
173
  <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.62",
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.62.1",
41
+ "sass-loader": "^13.2.2",
42
+ "vue": "^3.3.1",
43
+ "vue-router": "^4.2.0",
44
+ "@vuepress/client": "2.0.0-beta.62",
45
+ "@vuepress/core": "2.0.0-beta.62",
46
+ "@vuepress/plugin-container": "2.0.0-beta.62",
47
+ "@vuepress/plugin-git": "2.0.0-beta.62",
48
+ "@vuepress/plugin-active-header-links": "2.0.0-beta.62",
49
+ "@vuepress/plugin-back-to-top": "2.0.0-beta.62",
50
+ "@vuepress/plugin-palette": "2.0.0-beta.62",
51
+ "@vuepress/plugin-theme-data": "2.0.0-beta.62",
52
+ "@vuepress/shared": "2.0.0-beta.62",
53
+ "@vuepress/plugin-prismjs": "2.0.0-beta.62",
54
+ "@vuepress/utils": "2.0.0-beta.62",
55
+ "@vuepress/plugin-medium-zoom": "2.0.0-beta.62",
56
+ "@vuepress/plugin-nprogress": "2.0.0-beta.62",
57
+ "@vuepress/plugin-external-link-icon": "2.0.0-beta.62"
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": {