diff --git a/registry/lib/components/live/badge-helper/index.ts b/registry/lib/components/live/badge-helper/index.ts index bd3ed7f9c..3718d8b08 100644 --- a/registry/lib/components/live/badge-helper/index.ts +++ b/registry/lib/components/live/badge-helper/index.ts @@ -1,5 +1,5 @@ import { ComponentMetadata } from '@/components/types' -import { getUID, none } from '@/core/utils' +import { getNumberValidator, getUID, none } from '@/core/utils' import { autoMatchMedal } from './auto-match' export const component: ComponentMetadata = { @@ -26,7 +26,7 @@ export const component: ComponentMetadata = { maxBadgeCount: { defaultValue: 256, displayName: '最大加载数量', - validator: (value: number) => lodash.clamp(value, 1, 256), + validator: getNumberValidator(1, 256), }, defaultMedalID: { displayName: '默认勋章ID', diff --git a/registry/lib/components/style/auto-hide-sidebar/index.ts b/registry/lib/components/style/auto-hide-sidebar/index.ts index 9ae611c05..510cf3c30 100644 --- a/registry/lib/components/style/auto-hide-sidebar/index.ts +++ b/registry/lib/components/style/auto-hide-sidebar/index.ts @@ -1,5 +1,6 @@ import { ComponentMetadata } from '@/components/types' import { addComponentListener } from '@/core/settings' +import { getNumberValidator } from '@/core/utils' export const component: ComponentMetadata = { name: 'autoHideSidebar', @@ -21,7 +22,7 @@ export const component: ComponentMetadata = { triggerWidth: { defaultValue: 8, displayName: '触发区域宽度 (px)', - validator: (value: number) => lodash.clamp(value, 1, 1000), + validator: getNumberValidator(1, 1000), }, }, description: { diff --git a/registry/lib/components/style/home-redesign/fresh/index.ts b/registry/lib/components/style/home-redesign/fresh/index.ts index e8f82d206..30433d8dc 100644 --- a/registry/lib/components/style/home-redesign/fresh/index.ts +++ b/registry/lib/components/style/home-redesign/fresh/index.ts @@ -1,6 +1,7 @@ import { ComponentMetadata } from '@/components/types' import { contentLoaded } from '@/core/life-cycle' -import { mountVueComponent } from '@/core/utils' +import { addComponentListener } from '@/core/settings' +import { getNumberValidator, mountVueComponent } from '@/core/utils' import { homeUrls } from '../urls' export const component: ComponentMetadata = { @@ -18,6 +19,9 @@ export const component: ComponentMetadata = { componentsTags.style, ], entry: () => { + addComponentListener('freshHome.maxWidth', (width: number) => { + document.documentElement.style.setProperty('--home-max-width-override', `${width}px`) + }, true) contentLoaded(async () => { const FreshHome = await import('./FreshHome.vue') const freshHome = mountVueComponent(FreshHome) @@ -45,6 +49,11 @@ export const component: ComponentMetadata = { displayName: '启用横向滚动', defaultValue: false, }, + maxWidth: { + displayName: '最大宽度 (px)', + defaultValue: 1440, + validator: getNumberValidator(1000, 3000), + }, }, unload: () => document.body.classList.add('home-redesign-off'), reload: () => document.body.classList.remove('home-redesign-off'), diff --git a/registry/lib/components/style/sidebar-offset/index.ts b/registry/lib/components/style/sidebar-offset/index.ts index 8b5a3bac0..f24d12d3e 100644 --- a/registry/lib/components/style/sidebar-offset/index.ts +++ b/registry/lib/components/style/sidebar-offset/index.ts @@ -1,5 +1,6 @@ import { ComponentMetadata } from '@/components/types' import { addComponentListener } from '@/core/settings' +import { getNumberValidator } from '@/core/utils' export const component: ComponentMetadata = { name: 'sidebarOffset', @@ -23,7 +24,7 @@ export const component: ComponentMetadata = { offset: { displayName: '偏移量 (%)', defaultValue: 0, - validator: (value: number) => lodash.clamp(value, -40, 40), + validator: getNumberValidator(-40, 40), }, }, } diff --git a/src/core/utils/index.ts b/src/core/utils/index.ts index 02e290cf8..f361bd582 100644 --- a/src/core/utils/index.ts +++ b/src/core/utils/index.ts @@ -459,3 +459,13 @@ export const disableWindowScroll = async (action?: () => unknown | Promise ( + (value: number, oldValue: number) => ( + lodash.isNumber(value) ? lodash.clamp(value, clampLower, clampUpper) : oldValue + ) +)