refactoring
This commit is contained in:
@@ -2,64 +2,21 @@ import cloneDeep from 'clone-deep'
|
|||||||
import { Plugin } from 'prosemirror-state'
|
import { Plugin } from 'prosemirror-state'
|
||||||
import { Editor, CommandSpec } from './Editor'
|
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 = {
|
type AnyObject = {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|
||||||
type NoInfer<T> = [T][T extends any ? 0 : never]
|
type NoInfer<T> = [T][T extends any ? 0 : never]
|
||||||
|
|
||||||
|
type MergeStrategy = 'extend' | 'overwrite'
|
||||||
|
|
||||||
|
type Configs = {
|
||||||
|
[key: string]: {
|
||||||
|
stategy: MergeStrategy
|
||||||
|
value: any
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface ExtensionCallback<Options> {
|
export interface ExtensionCallback<Options> {
|
||||||
name: string
|
name: string
|
||||||
editor: Editor
|
editor: Editor
|
||||||
@@ -84,16 +41,11 @@ export default class Extension<
|
|||||||
Extends extends ExtensionExtends<Callback, Options> = ExtensionExtends<Callback, Options>
|
Extends extends ExtensionExtends<Callback, Options> = ExtensionExtends<Callback, Options>
|
||||||
> {
|
> {
|
||||||
type = 'extension'
|
type = 'extension'
|
||||||
config: any = {}
|
config: AnyObject = {}
|
||||||
configs: {
|
configs: Configs = {}
|
||||||
[key: string]: {
|
options: Partial<Options> = {}
|
||||||
stategy: 'extend' | 'overwrite'
|
|
||||||
value: any
|
|
||||||
}[]
|
|
||||||
} = {}
|
|
||||||
usedOptions: Partial<Options> = {}
|
|
||||||
|
|
||||||
protected storeConfig(key: string, value: any, stategy: 'extend' | 'overwrite') {
|
protected storeConfig(key: string, value: any, stategy: MergeStrategy) {
|
||||||
const item = {
|
const item = {
|
||||||
stategy,
|
stategy,
|
||||||
value,
|
value,
|
||||||
@@ -107,7 +59,7 @@ export default class Extension<
|
|||||||
}
|
}
|
||||||
|
|
||||||
public configure(options: Partial<Options>) {
|
public configure(options: Partial<Options>) {
|
||||||
this.usedOptions = { ...this.usedOptions, ...options }
|
this.options = { ...this.options, ...options }
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export default class ExtensionManager {
|
|||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
editor,
|
editor,
|
||||||
options: deepmerge(extension.config.defaults, extension.usedOptions),
|
options: deepmerge(extension.config.defaults, extension.options),
|
||||||
// TODO: type is not available here
|
// TODO: type is not available here
|
||||||
// get type() {
|
// get type() {
|
||||||
// console.log('called', editor.schema)
|
// console.log('called', editor.schema)
|
||||||
|
|||||||
Reference in New Issue
Block a user