mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-29 08:19:34 +08:00
refactoring
This commit is contained in:
parent
39082b9b99
commit
9a1f99ba4c
@ -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][T extends any ? 0 : never]
|
||||
|
||||
type MergeStrategy = 'extend' | 'overwrite'
|
||||
|
||||
type Configs = {
|
||||
[key: string]: {
|
||||
stategy: MergeStrategy
|
||||
value: any
|
||||
}[]
|
||||
}
|
||||
|
||||
export interface ExtensionCallback<Options> {
|
||||
name: string
|
||||
editor: Editor
|
||||
@ -84,16 +41,11 @@ export default class Extension<
|
||||
Extends extends ExtensionExtends<Callback, Options> = ExtensionExtends<Callback, Options>
|
||||
> {
|
||||
type = 'extension'
|
||||
config: any = {}
|
||||
configs: {
|
||||
[key: string]: {
|
||||
stategy: 'extend' | 'overwrite'
|
||||
value: any
|
||||
}[]
|
||||
} = {}
|
||||
usedOptions: Partial<Options> = {}
|
||||
config: AnyObject = {}
|
||||
configs: Configs = {}
|
||||
options: Partial<Options> = {}
|
||||
|
||||
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<Options>) {
|
||||
this.usedOptions = { ...this.usedOptions, ...options }
|
||||
this.options = { ...this.options, ...options }
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user