Specify the return type of method getGeneralSettings

This commit is contained in:
timongh 2022-03-21 19:06:32 +08:00
parent c68acc079d
commit 5678c19868
2 changed files with 24 additions and 11 deletions

View File

@ -5,11 +5,16 @@ import { CdnTypes } from '@/core/cdn-types'
import { addComponentListener } from '@/core/settings' import { addComponentListener } from '@/core/settings'
import { DownloadPackageEmitMode } from '@/core/download-mode' import { DownloadPackageEmitMode } from '@/core/download-mode'
import { ComponentEntry, componentsTags } from '../types' import { ComponentEntry, componentsTags } from '../types'
import { defineOptionsMetadata, defineComponentMetadata } from '../define' import {
defineComponentMetadata,
defineOptionsMetadata,
OptionsOfMetadata,
} from '../define'
import { provideActions } from './external-actions' import { provideActions } from './external-actions'
import description from './desc.md' import description from './desc.md'
export const WidgetsPlugin = 'widgets' export const WidgetsPlugin = 'widgets'
export enum SettingsPanelDockSide { export enum SettingsPanelDockSide {
Left = '左侧', Left = '左侧',
Right = '右侧', Right = '右侧',
@ -65,14 +70,23 @@ const options = defineOptionsMetadata({
}, },
}) })
export type Options = OptionsOfMetadata<typeof options>
const entry: ComponentEntry<typeof options> = async ({ metadata }) => { const entry: ComponentEntry<typeof options> = async ({ metadata }) => {
const { isIframe } = await import('@/core/utils') const { isIframe } = await import('@/core/utils')
if (isIframe()) { if (isIframe()) {
return return
} }
addComponentListener(`${metadata.name}.dockSide`, (value: SettingsPanelDockSide) => { addComponentListener(
document.body.classList.toggle('settings-panel-dock-right', value === SettingsPanelDockSide.Right) `${metadata.name}.dockSide`,
}, true) (value: SettingsPanelDockSide) => {
document.body.classList.toggle(
'settings-panel-dock-right',
value === SettingsPanelDockSide.Right,
)
},
true,
)
requestIdleCallback(async () => { requestIdleCallback(async () => {
const Container = await import('./SettingsContainer.vue') const Container = await import('./SettingsContainer.vue')
const instance = mountVueComponent(Container) const instance = mountVueComponent(Container)

View File

@ -8,7 +8,8 @@ import {
} from '@/components/component' } from '@/components/component'
import { PluginMetadata } from '@/plugins/plugin' import { PluginMetadata } from '@/plugins/plugin'
// import serialize from 'serialize-javascript' // import serialize from 'serialize-javascript'
import { settings, ComponentSettings } from '../settings' import type { Options as SettingsPanelOptions } from '@/components/settings-panel'
import { ComponentSettings, settings } from '../settings'
import { matchUrlPattern } from '../utils' import { matchUrlPattern } from '../utils'
/** /**
@ -23,11 +24,9 @@ export const metadataToOptions = <O extends UnknownOptions>(
* *
* @param component * @param component
*/ */
export const componentToSettings = < export const componentToSettings = <Om extends OptionalOptionsMetadata>(
Om extends OptionalOptionsMetadata component: ComponentMetadata<Om>,
>(component: ComponentMetadata<Om>): ( ): ComponentSettings<OptionsFromOptionalMetadata<Om>> => {
ComponentSettings<OptionsFromOptionalMetadata<Om>>
) => {
const { options: meta } = component const { options: meta } = component
return { return {
enabled: component.enabledByDefault ?? true, enabled: component.enabledByDefault ?? true,
@ -99,7 +98,7 @@ export const getComponentSettings = <R extends UnknownOptions = UnknownOptions>(
/** /**
* (`settingsPanel``options`) * (`settingsPanel``options`)
*/ */
export const getGeneralSettings = () => getComponentSettings('settingsPanel').options export const getGeneralSettings = () => getComponentSettings<SettingsPanelOptions>('settingsPanel').options
/** /**
* , : * , :
* - , URL必须不匹配其排除列表中任意一项(`Component.urlExclude`) * - , URL必须不匹配其排除列表中任意一项(`Component.urlExclude`)