Skip to content

Commit

Permalink
fix(enhanced-readabilities): fallback to default value when layout mo…
Browse files Browse the repository at this point in the history
…de value isn't supported

Signed-off-by: Neko Ayaka <[email protected]>
  • Loading branch information
nekomeowww committed Nov 10, 2023
1 parent 0e45659 commit 4d95e2d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import { onMounted, ref, watch, inject } from 'vue'
import { useLocalStorage, useMediaQuery, useMounted } from '@vueuse/core'
import { InjectionKey, LayoutSwitchModeStorageKey } from '../constants'
import { InjectionKey, LayoutSwitchModeStorageKey, LayoutMode, supportedLayoutModes } from '../constants'
import { useLayoutAppearanceChangeAnimation } from '../composables/animation'
import { useI18n } from '../composables/i18n'
import { LayoutMode } from '../types'
import MenuOption from './MenuOption.vue'
import MenuTitle from './MenuTitle.vue'
Expand Down Expand Up @@ -57,13 +56,19 @@ watch(mounted, (val) => {
return
setClasses(layoutMode.value, false)
if (!supportedLayoutModes.includes(layoutMode.value)) {
layoutMode.value = options.layoutSwitch?.defaultMode || LayoutMode.BothWidthAdjustable
}
})
watch(layoutMode, (val) => {
if (!mounted.value)
return
setClasses(val, true)
if (!supportedLayoutModes.includes(val)) {
layoutMode.value = options.layoutSwitch?.defaultMode || LayoutMode.BothWidthAdjustable
}
})
watch(isLargerThanMobile, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import { computed, inject, onMounted, ref, watch } from 'vue'
import { useDebounceFn, useLocalStorage, useMediaQuery, useMounted, useStorage } from '@vueuse/core'
import { InjectionKey, ContentLayoutMaxWidthStorageKey, LayoutSwitchModeStorageKey } from '../constants'
import { InjectionKey, ContentLayoutMaxWidthStorageKey, LayoutSwitchModeStorageKey, LayoutMode } from '../constants'
import { useLayoutAppearanceChangeAnimation } from '../composables/animation'
import { useI18n } from '../composables/i18n'
import { LayoutMode } from '../types'
import MenuTitle from './MenuTitle.vue'
import MenuHelp from './MenuHelp.vue'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import { computed, inject, onMounted, ref, watch } from 'vue'
import { useDebounceFn, useLocalStorage, useMediaQuery, useMounted, useStorage } from '@vueuse/core'
import { InjectionKey, LayoutSwitchModeStorageKey, PageLayoutMaxWidthStorageKey } from '../constants'
import { InjectionKey, LayoutMode, LayoutSwitchModeStorageKey, PageLayoutMaxWidthStorageKey } from '../constants'
import { useLayoutAppearanceChangeAnimation } from '../composables/animation'
import { useI18n } from '../composables/i18n'
import { LayoutMode } from '../types'
import MenuTitle from './MenuTitle.vue'
import MenuHelp from './MenuHelp.vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { LayoutMode } from '../types'
import { onMounted, ref, watch } from 'vue'
import { useMediaQuery } from '@vueuse/core'
import { useI18n } from '../composables/i18n'
import { LayoutMode } from '../constants'
import MenuTitle from './MenuTitle.vue'
import MenuOption from './MenuOption.vue'
import { useMediaQuery } from '@vueuse/core'
import { onMounted, ref, watch } from 'vue'
const disabled = ref(true)
Expand Down
14 changes: 14 additions & 0 deletions packages/vitepress-plugin-enhanced-readabilities/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ export const LayoutSwitchMaxWidthStrategyStorageKey = 'vitepress-nolebase-enhanc
export const ContentLayoutMaxWidthStorageKey = 'vitepress-nolebase-enhanced-readabilities-content-layout-max-width'
export const PageLayoutMaxWidthStorageKey = 'vitepress-nolebase-enhanced-readabilities-page-layout-max-width'
export const SpotlightToggledStorageKey = 'vitepress-nolebase-enhanced-readabilities-spotlight-mode'

export enum LayoutMode {
FullWidth = 1,
Original = 3,
SidebarWidthAdjustableOnly = 4,
BothWidthAdjustable = 5,
}

export const supportedLayoutModes = [
LayoutMode.FullWidth,
LayoutMode.Original,
LayoutMode.SidebarWidthAdjustableOnly,
LayoutMode.BothWidthAdjustable,
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import type {
Options,
} from './types'

import {
LayoutMode,
} from './types'

import {
InjectionKey,
LayoutMode,
LayoutSwitchModeStorageKey,
SpotlightToggledStorageKey,
} from './constants'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
export enum LayoutMode {
FullWidth = 1,
Original = 3,
SidebarWidthAdjustableOnly = 4,
BothWidthAdjustable = 5,
}
import type { LayoutMode } from './constants'

/**
* Locale
Expand Down

0 comments on commit 4d95e2d

Please sign in to comment.