Skip to content

Commit ebbe3b2

Browse files
authored
fix(enhanced-readabilities): fallback to default value when layout mode value isn't supported (#12)
* fix(enhanced-readabilities): fallback to default value when layout mode value isn't supported * docs(enhanced-readabilities): updated docs Signed-off-by: Neko Ayaka <neko@ayaka.moe>
1 parent 3b70435 commit ebbe3b2

9 files changed

Lines changed: 94 additions & 29 deletions

File tree

docs/pages/en/integrations/vitepress-plugin-enhanced-readabilities/index.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ export interface Locale {
534534
*/
535535
titleAriaLabel?: string
536536
/**
537-
* Title help message
537+
* Title descriptive help message
538538
*/
539539
titleHelpMessage?: string
540540
/**
@@ -603,15 +603,24 @@ export interface Locale {
603603
*/
604604
titleAriaLabel?: string
605605
/**
606-
* Title help message
606+
* Title descriptive help message
607607
*/
608608
titleHelpMessage?: string
609609
/**
610610
* Title warning message for navigation menu in small screen
611611
*/
612612
titleScreenNavWarningMessage?: string
613+
/**
614+
* Content layout max width slider functionality title in help tooltip popup
615+
*/
613616
slider?: string
617+
/**
618+
* Content layout max width slider functionality aria-label in help tooltip popup
619+
*/
614620
sliderAriaLabel?: string
621+
/**
622+
* Content layout max width slider functionality descriptive help message in help tooltip popup
623+
*/
615624
sliderHelpMessage?: string
616625
}
617626
/**
@@ -627,15 +636,24 @@ export interface Locale {
627636
*/
628637
titleAriaLabel?: string
629638
/**
630-
* Title help message
639+
* Title descriptive help message
631640
*/
632641
titleHelpMessage?: string
633642
/**
634643
* Title warning message for navigation menu in small screen
635644
*/
636645
titleScreenNavWarningMessage?: string
646+
/**
647+
* Page layout max width slider functionality title in help tooltip popup
648+
*/
637649
slider?: string
650+
/**
651+
* Page layout max width slider functionality aria-label in help tooltip popup
652+
*/
638653
sliderAriaLabel?: string
654+
/**
655+
* Page layout max width slider functionality descriptive help message in help tooltip popup
656+
*/
639657
sliderHelpMessage?: string
640658
}
641659
}

docs/pages/zh-CN/integrations/vitepress-plugin-enhanced-readabilities/index.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export interface Locale {
533533
*/
534534
titleAriaLabel?: string
535535
/**
536-
* Title help message
536+
* Title descriptive help message
537537
*/
538538
titleHelpMessage?: string
539539
/**
@@ -602,15 +602,24 @@ export interface Locale {
602602
*/
603603
titleAriaLabel?: string
604604
/**
605-
* Title help message
605+
* Title descriptive help message
606606
*/
607607
titleHelpMessage?: string
608608
/**
609609
* Title warning message for navigation menu in small screen
610610
*/
611611
titleScreenNavWarningMessage?: string
612+
/**
613+
* Content layout max width slider functionality title in help tooltip popup
614+
*/
612615
slider?: string
616+
/**
617+
* Content layout max width slider functionality aria-label in help tooltip popup
618+
*/
613619
sliderAriaLabel?: string
620+
/**
621+
* Content layout max width slider functionality descriptive help message in help tooltip popup
622+
*/
614623
sliderHelpMessage?: string
615624
}
616625
/**
@@ -626,15 +635,24 @@ export interface Locale {
626635
*/
627636
titleAriaLabel?: string
628637
/**
629-
* Title help message
638+
* Title descriptive help message
630639
*/
631640
titleHelpMessage?: string
632641
/**
633642
* Title warning message for navigation menu in small screen
634643
*/
635644
titleScreenNavWarningMessage?: string
645+
/**
646+
* Page layout max width slider functionality title in help tooltip popup
647+
*/
636648
slider?: string
649+
/**
650+
* Page layout max width slider functionality aria-label in help tooltip popup
651+
*/
637652
sliderAriaLabel?: string
653+
/**
654+
* Page layout max width slider functionality descriptive help message in help tooltip popup
655+
*/
638656
sliderHelpMessage?: string
639657
}
640658
}

packages/vitepress-plugin-enhanced-readabilities/src/components/LayoutSwitch.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import { onMounted, ref, watch, inject } from 'vue'
33
import { useLocalStorage, useMediaQuery, useMounted } from '@vueuse/core'
44
5-
import { InjectionKey, LayoutSwitchModeStorageKey } from '../constants'
5+
import { InjectionKey, LayoutSwitchModeStorageKey, LayoutMode, supportedLayoutModes } from '../constants'
66
import { useLayoutAppearanceChangeAnimation } from '../composables/animation'
77
import { useI18n } from '../composables/i18n'
8-
import { LayoutMode } from '../types'
98
109
import MenuOption from './MenuOption.vue'
1110
import MenuTitle from './MenuTitle.vue'
@@ -57,13 +56,19 @@ watch(mounted, (val) => {
5756
return
5857
5958
setClasses(layoutMode.value, false)
59+
if (!supportedLayoutModes.includes(layoutMode.value)) {
60+
layoutMode.value = options.layoutSwitch?.defaultMode || LayoutMode.BothWidthAdjustable
61+
}
6062
})
6163
6264
watch(layoutMode, (val) => {
6365
if (!mounted.value)
6466
return
6567
6668
setClasses(val, true)
69+
if (!supportedLayoutModes.includes(val)) {
70+
layoutMode.value = options.layoutSwitch?.defaultMode || LayoutMode.BothWidthAdjustable
71+
}
6772
})
6873
6974
watch(isLargerThanMobile, () => {

packages/vitepress-plugin-enhanced-readabilities/src/components/LayoutSwitchContentLayoutMaxWidthSlider.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import { computed, inject, onMounted, ref, watch } from 'vue'
33
import { useDebounceFn, useLocalStorage, useMediaQuery, useMounted, useStorage } from '@vueuse/core'
44
5-
import { InjectionKey, ContentLayoutMaxWidthStorageKey, LayoutSwitchModeStorageKey } from '../constants'
5+
import { InjectionKey, ContentLayoutMaxWidthStorageKey, LayoutSwitchModeStorageKey, LayoutMode } from '../constants'
66
import { useLayoutAppearanceChangeAnimation } from '../composables/animation'
77
import { useI18n } from '../composables/i18n'
8-
import { LayoutMode } from '../types'
98
109
import MenuTitle from './MenuTitle.vue'
1110
import MenuHelp from './MenuHelp.vue'

packages/vitepress-plugin-enhanced-readabilities/src/components/LayoutSwitchPageLayoutMaxWidthSlider.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import { computed, inject, onMounted, ref, watch } from 'vue'
33
import { useDebounceFn, useLocalStorage, useMediaQuery, useMounted, useStorage } from '@vueuse/core'
44
5-
import { InjectionKey, LayoutSwitchModeStorageKey, PageLayoutMaxWidthStorageKey } from '../constants'
5+
import { InjectionKey, LayoutMode, LayoutSwitchModeStorageKey, PageLayoutMaxWidthStorageKey } from '../constants'
66
import { useLayoutAppearanceChangeAnimation } from '../composables/animation'
77
import { useI18n } from '../composables/i18n'
8-
import { LayoutMode } from '../types'
98
109
import MenuTitle from './MenuTitle.vue'
1110
import MenuHelp from './MenuHelp.vue'

packages/vitepress-plugin-enhanced-readabilities/src/components/ScreenLayoutSwitch.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
2-
import { LayoutMode } from '../types'
2+
import { onMounted, ref, watch } from 'vue'
3+
import { useMediaQuery } from '@vueuse/core'
4+
35
import { useI18n } from '../composables/i18n'
6+
import { LayoutMode } from '../constants'
7+
48
import MenuTitle from './MenuTitle.vue'
59
import MenuOption from './MenuOption.vue'
6-
import { useMediaQuery } from '@vueuse/core'
7-
import { onMounted, ref, watch } from 'vue'
810
911
const disabled = ref(true)
1012

packages/vitepress-plugin-enhanced-readabilities/src/constants.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ export const LayoutSwitchMaxWidthStrategyStorageKey = 'vitepress-nolebase-enhanc
88
export const ContentLayoutMaxWidthStorageKey = 'vitepress-nolebase-enhanced-readabilities-content-layout-max-width'
99
export const PageLayoutMaxWidthStorageKey = 'vitepress-nolebase-enhanced-readabilities-page-layout-max-width'
1010
export const SpotlightToggledStorageKey = 'vitepress-nolebase-enhanced-readabilities-spotlight-mode'
11+
12+
export enum LayoutMode {
13+
FullWidth = 1,
14+
Original = 3,
15+
SidebarWidthAdjustableOnly = 4,
16+
BothWidthAdjustable = 5,
17+
}
18+
19+
export const supportedLayoutModes = [
20+
LayoutMode.FullWidth,
21+
LayoutMode.Original,
22+
LayoutMode.SidebarWidthAdjustableOnly,
23+
LayoutMode.BothWidthAdjustable,
24+
]

packages/vitepress-plugin-enhanced-readabilities/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import type {
44
Options,
55
} from './types'
66

7-
import {
8-
LayoutMode,
9-
} from './types'
10-
117
import {
128
InjectionKey,
9+
LayoutMode,
1310
LayoutSwitchModeStorageKey,
1411
SpotlightToggledStorageKey,
1512
} from './constants'

packages/vitepress-plugin-enhanced-readabilities/src/types.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
export enum LayoutMode {
2-
FullWidth = 1,
3-
Original = 3,
4-
SidebarWidthAdjustableOnly = 4,
5-
BothWidthAdjustable = 5,
6-
}
1+
import type { LayoutMode } from './constants'
72

83
/**
94
* Locale
@@ -39,7 +34,7 @@ export interface Locale {
3934
*/
4035
titleAriaLabel?: string
4136
/**
42-
* Title help message
37+
* Title descriptive help message
4338
*/
4439
titleHelpMessage?: string
4540
/**
@@ -108,15 +103,24 @@ export interface Locale {
108103
*/
109104
titleAriaLabel?: string
110105
/**
111-
* Title help message
106+
* Title descriptive help message
112107
*/
113108
titleHelpMessage?: string
114109
/**
115110
* Title warning message for navigation menu in small screen
116111
*/
117112
titleScreenNavWarningMessage?: string
113+
/**
114+
* Content layout max width slider functionality title in help tooltip popup
115+
*/
118116
slider?: string
117+
/**
118+
* Content layout max width slider functionality aria-label in help tooltip popup
119+
*/
119120
sliderAriaLabel?: string
121+
/**
122+
* Content layout max width slider functionality descriptive help message in help tooltip popup
123+
*/
120124
sliderHelpMessage?: string
121125
}
122126
/**
@@ -132,15 +136,24 @@ export interface Locale {
132136
*/
133137
titleAriaLabel?: string
134138
/**
135-
* Title help message
139+
* Title descriptive help message
136140
*/
137141
titleHelpMessage?: string
138142
/**
139143
* Title warning message for navigation menu in small screen
140144
*/
141145
titleScreenNavWarningMessage?: string
146+
/**
147+
* Page layout max width slider functionality title in help tooltip popup
148+
*/
142149
slider?: string
150+
/**
151+
* Page layout max width slider functionality aria-label in help tooltip popup
152+
*/
143153
sliderAriaLabel?: string
154+
/**
155+
* Page layout max width slider functionality descriptive help message in help tooltip popup
156+
*/
144157
sliderHelpMessage?: string
145158
}
146159
}
@@ -236,7 +249,7 @@ export interface Options {
236249
/**
237250
* Default mode for layout switch
238251
*
239-
* @default LayoutMode.FitContentWidth (3)
252+
* @default LayoutMode.BothWidthAdjustable (4)
240253
*/
241254
defaultMode?: LayoutMode
242255
/**

0 commit comments

Comments
 (0)