import type { Editor } from './Editor.js' import { type ExtendableConfig, Extendable } from './Extendable.js' // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface ExtensionConfig extends ExtendableConfig, null> {} /** * The Extension class is the base class for all extensions. * @see https://tiptap.dev/api/extensions#create-a-new-extension */ export class Extension extends Extendable< Options, Storage, ExtensionConfig > { type = 'extension' /** * Create a new Extension instance * @param config - Extension configuration object or a function that returns a configuration object */ static create( config: Partial> | (() => Partial>) = {}, ) { // If the config is a function, execute it to get the configuration object const resolvedConfig = typeof config === 'function' ? config() : config return new Extension(resolvedConfig) } configure(options?: Partial) { return super.configure(options) as Extension } extend< ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = ExtensionConfig, >( extendedConfig?: | (() => Partial) | (Partial & ThisType<{ name: string options: ExtendedOptions storage: ExtendedStorage editor: Editor type: null }>), ): Extension { // If the extended config is a function, execute it to get the configuration object const resolvedConfig = typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig return super.extend(resolvedConfig) as Extension } }