diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index bb1114ec..27b44d39 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -2,64 +2,21 @@ import cloneDeep from 'clone-deep' import { Plugin } from 'prosemirror-state' import { Editor, CommandSpec } from './Editor' -// export default abstract class Extension { - -// constructor(options = {}) { -// this.options = { -// ...this.defaultOptions(), -// ...options, -// } -// } - -// editor!: Editor -// options: { [key: string]: any } = {} - -// public abstract name: string - -// public extensionType = 'extension' - -// public created() {} - -// public bindEditor(editor: Editor): void { -// this.editor = editor -// } - -// defaultOptions(): { [key: string]: any } { -// return {} -// } - -// update(): any { -// return () => {} -// } - -// plugins(): Plugin[] { -// return [] -// } - -// inputRules(): any { -// return [] -// } - -// pasteRules(): any { -// return [] -// } - -// keys(): { [key: string]: Function } { -// return {} -// } - -// commands(): { [key: string]: Command } { -// return {} -// } - -// } - type AnyObject = { [key: string]: any } type NoInfer = [T][T extends any ? 0 : never] +type MergeStrategy = 'extend' | 'overwrite' + +type Configs = { + [key: string]: { + stategy: MergeStrategy + value: any + }[] +} + export interface ExtensionCallback { name: string editor: Editor @@ -84,16 +41,11 @@ export default class Extension< Extends extends ExtensionExtends = ExtensionExtends > { type = 'extension' - config: any = {} - configs: { - [key: string]: { - stategy: 'extend' | 'overwrite' - value: any - }[] - } = {} - usedOptions: Partial = {} + config: AnyObject = {} + configs: Configs = {} + options: Partial = {} - protected storeConfig(key: string, value: any, stategy: 'extend' | 'overwrite') { + protected storeConfig(key: string, value: any, stategy: MergeStrategy) { const item = { stategy, value, @@ -107,7 +59,7 @@ export default class Extension< } public configure(options: Partial) { - this.usedOptions = { ...this.usedOptions, ...options } + this.options = { ...this.options, ...options } return this } diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 82b7cc5f..ff2d6578 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -35,7 +35,7 @@ export default class ExtensionManager { ? undefined : { editor, - options: deepmerge(extension.config.defaults, extension.usedOptions), + options: deepmerge(extension.config.defaults, extension.options), // TODO: type is not available here // get type() { // console.log('called', editor.schema)