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

View File

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