UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

88 lines (87 loc) 3.06 kB
/** * @packageDocumentation * * Types helpers for plugin types. */ import type { ReadonlyDeep } from 'type-fest'; import type { PropertyValues, StringKeys } from '../../Type.mjs'; import type { DefaultTranslationsBase } from '../i18n/DefaultTranslationsBase.mjs'; import type { PluginBase } from './PluginBase.mjs'; import type { PluginSettingsManagerBase } from './PluginSettingsManagerBase.mjs'; import type { PluginSettingsTabBase } from './PluginSettingsTabBase.mjs'; import type { PluginSettingsWrapper } from './PluginSettingsWrapper.mjs'; /** * Extracts the plugin from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPlugin<PluginTypes extends PluginTypesBase> = PluginTypes['plugin']; /** * Extracts the plugin settings from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPluginSettings<PluginTypes extends PluginTypesBase> = PluginTypes['pluginSettings']; /** * Extracts the plugin settings manager from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPluginSettingsManager<PluginTypes extends PluginTypesBase> = PluginTypes['pluginSettingsManager']; /** * Extracts the plugin settings property names from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPluginSettingsPropertyNames<PluginTypes extends PluginTypesBase> = StringKeys<ExtractPluginSettings<PluginTypes>>; /** * Extracts the plugin settings property values from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPluginSettingsPropertyValues<PluginTypes extends PluginTypesBase> = PropertyValues<ExtractPluginSettings<PluginTypes>>; /** * Extracts the plugin settings tab from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPluginSettingsTab<PluginTypes extends PluginTypesBase> = PluginTypes['pluginSettingsTab']; /** * Extracts the plugin settings wrapper from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractPluginSettingsWrapper<PluginTypes extends PluginTypesBase> = PluginSettingsWrapper<ExtractPluginSettings<PluginTypes>>; /** * Extracts the readonly plugin settings wrapper from the plugin types. * * @typeParam PluginTypes - The plugin types. */ export type ExtractReadonlyPluginSettingsWrapper<PluginTypes extends PluginTypesBase> = ReadonlyDeep<ExtractPluginSettingsWrapper<PluginTypes>>; /** * A base type for plugin types. * * An interface is used only for type inference. */ export interface PluginTypesBase { /** * Default translations. */ defaultTranslations: DefaultTranslationsBase; /** * A plugin. */ plugin: PluginBase<PluginTypesBase>; /** * A plugin settings. */ pluginSettings: object; /** * A plugin settings manager. */ pluginSettingsManager: PluginSettingsManagerBase<any>; /** * A plugin settings tab. */ pluginSettingsTab: PluginSettingsTabBase<any>; }