From 5678c19868f6989c57ecdbfebf872b67b343f074 Mon Sep 17 00:00:00 2001 From: timongh <46739861+timongh@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:06:32 +0800 Subject: [PATCH] Specify the return type of method getGeneralSettings --- src/components/settings-panel/index.ts | 22 ++++++++++++++++++---- src/core/settings/helpers.ts | 13 ++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/components/settings-panel/index.ts b/src/components/settings-panel/index.ts index bf806f9bb..bd19c8845 100644 --- a/src/components/settings-panel/index.ts +++ b/src/components/settings-panel/index.ts @@ -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 + const entry: ComponentEntry = 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) diff --git a/src/core/settings/helpers.ts b/src/core/settings/helpers.ts index 7c1ecc0e5..6874740e1 100644 --- a/src/core/settings/helpers.ts +++ b/src/core/settings/helpers.ts @@ -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 = ( * 生成组件设置 * @param component 组件定义 */ -export const componentToSettings = < - Om extends OptionalOptionsMetadata ->(component: ComponentMetadata): ( - ComponentSettings> -) => { +export const componentToSettings = ( + component: ComponentMetadata, +): ComponentSettings> => { const { options: meta } = component return { enabled: component.enabledByDefault ?? true, @@ -99,7 +98,7 @@ export const getComponentSettings = ( /** * 获取通用设置 (`settingsPanel`组件的`options`) */ -export const getGeneralSettings = () => getComponentSettings('settingsPanel').options +export const getGeneralSettings = () => getComponentSettings('settingsPanel').options /** * 判断此组件是否启用, 启用的条件为: * - 若定义了排除列表, 当前URL必须不匹配其排除列表中任意一项(`Component.urlExclude`)